【发布时间】:2021-09-29 05:44:42
【问题描述】:
我不明白为什么我的触发器不起作用。
第一个表:
CREATE TABLE `Payment` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`idPaymentMethod` int(20) DEFAULT NULL,
`createAt` timestamp NOT NULL DEFAULT current_timestamp(),
`updateAt` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE current_timestamp(),
`actived` tinyint(1) NOT NULL DEFAULT 1,
`numberInvoices` int(11) DEFAULT NULL,
`preferentialPaymentDay` int(11) DEFAULT NULL,
`invoicesFrequency` bigint(20) NOT NULL DEFAULT 0,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;
第二张桌子:
CREATE TABLE `PaymentHistory` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`idPaymentMethod` int(20) DEFAULT NULL,
`idPayment` int(20) DEFAULT NULL,
`createAt` timestamp NOT NULL DEFAULT current_timestamp(),
`updateAt` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE current_timestamp(),
`actived` tinyint(1) NOT NULL DEFAULT 1,
`numberInvoices` int(11) DEFAULT NULL,
`preferentialPaymentDay` int(11) DEFAULT NULL,
`invoicesFrequency` bigint(20) NOT NULL DEFAULT 0,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;
我的触发器:
DELIMITER $$
CREATE
TRIGGER `update_history` AFTER
UPDATE
ON
`Payment`
FOR EACH ROW BEGIN
UPDATE
`PaymentHistory`
SET
id = OLD.id,
idPaymentMethod = old.idPaymentMethod,
createAt = old.createAt,
updateAt = old.updateAt,
actived = old.actived,
numberInvoices = old.numberInvoices
END$$
当我尝试修复某些东西时,我遇到了很多错误。
我得到的错误:
SQL 错误 [1064] [42000]:您的 SQL 语法有错误;查看与您的 MariaDB 服务器版本相对应的手册,了解在第 1 行的“END$$”附近使用的正确语法
SQL 错误 [1054] [42S22]:“字段列表”中的未知列“OLD.id”
我真的迷路了。
我需要将“Payment”表中的所有更新数据插入或更新到“PaymentHistory”表中
请问,我需要帮助。
【问题讨论】: