共计 867 个字符,预计需要花费 3 分钟才能阅读完成。
今天工作需要,想要实现将仅对状态更新的表进行历史记录显示,于是考虑在原表中建立触发器,将更新的内容同时写入另一张表
于是进行测试
-- 建立测试表
CREATE TABLE `triggletest_triggle` (`id` INT(11) NOT NULL,
`name` VARCHAR(5) NULL DEFAULT NULL,
PRIMARY KEY (`id`)
)
COLLATE='latin1_swedish_ci'
ENGINE=InnoDB
-- 建立目标表
CREATE TABLE `triggletest` (`seq` INT(11) NOT NULL,
`id` INT(11) NOT NULL,
`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
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 */
问题待查
本文永久更新链接地址 :http://www.linuxidc.com/Linux/2016-07/132998.htm
正文完
星哥玩云-微信公众号