创建更新触发器以在MySQL语法错误中复制更改的数据

时间:2014-11-25 01:23:03

标签: mysql syntax triggers

CREATE TRIGGER backupFIDE AFTER UPDATE ON player
FOR EACH ROW
BEGIN
IF (OLD.FIDERating <> NEW.FIDERating) THEN
INSERT INTO playerbackup(PlayerName, OldFIDERating, NewFIDERating)
VALUES(OLD.PlayerName, OLD.FIDERating, NEW.NewFIDERating)
END;

大家好,因为某些原因在第6行收到语法错误,一直在网上寻找可能是原因的解决方案。基本上看一个简单的触发器,它会将Player表中FIDERating的更改更改复制到包含OldFIDERating的备份表,然后更改它,并进行NewFIDERating以及日期更改。

1 个答案:

答案 0 :(得分:0)

DELIMITER //
CREATE TRIGGER backupFIDE AFTER UPDATE ON player
FOR EACH ROW
BEGIN
IF NEW.FIDERating <> OLD.FIDERating
THEN
INSERT INTO playerbackup(PlayerName, OldFIDERating, NewFIDERating)
VALUES(OLD.PlayerName, OLD.FIDERating, NEW.NewFIDERating);
END IF;
END;
//
DELIMITER ;