我希望下面的内容会成功。但是SQL语法错误...... 显然,如果只更改特殊数据,我不想将数据插入表中。
CREATE TRIGGER `before_access_update` BEFORE UPDATE ON `access` FOR EACH ROW IF NOT (NEW.pin<>OLD.pin) THEN
INSERT INTO access_audit
SET action = 'update',
a_lastname = OLD.lastname,
a_firstname = OLD.firstname,
changed_on = NOW();
END IF;
答案 0 :(得分:1)
您在触发器中使用;
,因此您必须为触发器本身使用另一个查询分隔符:
DELIMITER $$
CREATE TRIGGER `before_access_update` BEFORE UPDATE ON `access` FOR EACH ROW IF NOT (NEW.pin<>OLD.pin) THEN
INSERT INTO access_audit
SET action = 'update',
a_lastname = OLD.lastname,
a_firstname = OLD.firstname,
changed_on = NOW();
END IF$$
DELIMITER ;