我想在我的数据库中复制旧记录。我尝试使用触发器,但有问题。我正在使用 MySQL Workbench,所以我发布了以下代码:
USE `secus_21`;
DELIMITER $$
CREATE TRIGGER `tsm_tasks_BUPD` BEFORE UPDATE ON tsm_tasks FOR EACH ROW
INSERT INTO `tsm_tasks_history`
( `ID_task` , `ID_user` , `ID_project` , `name` , `add_time` , `comment` )
VALUES
( OLD.`ID` , OLD.`ID_user` , OLD.`ID_project` , OLD.`name` , NOW() , OLD.`comment` );
更新事件,添加新记录,并尝试更改某些内容。我没有收到任何错误,所以我确定添加已成功完成,但tsm_tasks_history
表中仍然没有任何内容。
编辑:
这里是所有触发语句
-- Full Trigger DDL Statements
-- Note: Only CREATE TRIGGER statements are allowed
DELIMITER $$
USE `secus_21`$$
CREATE TRIGGER `tsm_tasks_BUPD` BEFORE UPDATE ON tsm_tasks FOR EACH ROW
-- Edit trigger body code below this line. Do not edit lines above this one
INSERT INTO `tsm_tasks_history`
( `ID_task` , `ID_user` , `ID_project` , `name` , `add_time` , `comment` )
VALUES
( OLD.`ID` , OLD.`ID_user` , OLD.`ID_project` , OLD.`name` , NOW() , OLD.`comment` )
$$
CREATE TRIGGER `tsm_tasks_BDEL` BEFORE DELETE ON tsm_tasks FOR EACH ROW
-- Edit trigger body code below this line. Do not edit lines above this one
INSERT INTO `tsm_tasks_history`
( `ID_task` , `ID_user` , `ID_project` , `name` , `add_time` , `comment` )
VALUES
( OLD.`ID` , OLD.`ID_user` , OLD.`ID_project` , OLD.`name` , NOW() , OLD.`comment` )
$$