Mysql Trigger IF目标字段已更改

时间:2012-03-31 06:55:31

标签: php mysql if-statement triggers conditional-statements

我想仅在某些字段被修改时才触发UPDATE触发器。 是否可以使用if语句;执行特定查询。

例子(不工作如图):

DROP TRIGGER IF EXISTS `catch_mytable_update`//
CREATE TRIGGER `catch_mytable_update` AFTER UPDATE ON `mytable`
 FOR EACH ROW BEGIN

IF (old.name != new.name) THEN

DELETE FROM trigger WHERE tablename='mytable' AND rowid = new.id;
INSERT INTO trigger (tablename, rowid, cmd, cmduser, time) VALUES('mytable', new.id, 'UPDATE', CURRENT_USER(), NOW());

ENDIF//

END//

分隔符://

1 个答案:

答案 0 :(得分:1)

尝试更改:

    IF (name.old != name.new) THEN

为:

    IF old.name != new.name THEN