MySQL触发器Update触发Insert失败
今天⼯作需要,想要实现将仅对状态更新的表进⾏历史记录显⽰,于是考虑在原表中建⽴触发器,将更新的内容同时写⼊另⼀张表
于是进⾏测试
--建⽴测试表CREATE TABLE `triggletest_triggle` (
`id` INT(11) NOT NULL,
`name` VARCHAR(5) NULL DEFAULT NULL,
PRIMARY KEY (`id`)
)
如何在excel中设置下拉菜单
COLLATE='latin1_swedish_ci'
ENGINE=InnoDB
--建⽴⽬标表
CREATE TABLE `triggletest` (
`seq` INT(11) NOT NULL,
`id` INT(11) NOT NULL,
junior韩宜邦>快乐青年
`name` VARCHAR(5) NULL DEFAULT NULL,
PRIMARY KEY (`seq`),
INDEX `id` (`id`)
)
COLLATE='latin1_swedish_ci'
ENGINE=InnoDB;
---写⼊测试数据
INSERT INTO `triggletest_triggle` VALUES(1,'A');
-
-建⽴触发器
DROP TRIGGER if EXISTS test1
CREATE TRIGGER test1配置windows update失败
AFTER UPDATE ON triggletest_triggle
FOR EACH ROW
BEGIN
聊搞笑图片INSERT INTO triggletest(id) values (new.id);
END
执⾏触发器语句,报错,报错内容如下:
/* SQL错误(1064):You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CREATE TRIGGER test1 AFTER UPDATE ON triggletest_triggle
FOR EACH ROW
BEGIN ' at line 2 */
---最终实现代码
DROP TRIGGER if EXISTS test1;
定点停车与坡道起步CREATE TRIGGER test1 AFTER UPDATE iggletest_triggle FOR EACH ROW
BEGIN
INSERT INTO triggletest(id,name) values (new.id,new.name);
END;
分析,由于访问⼯具HediSQL,导致⽆法正常创建触发器,相同语句,在HediSQL中执⾏,报错,使⽤shell调⽤mysql,直接执⾏程序,成功。