开发者

How to make a MySQL trigger run only when at least one OLD field is different from NEW fields?

I am trying to audit table changes on MySQL but I 开发者_运维问答want the "before update" trigger to run (add a line into an audit table) only when there is at least one changed field.

Is there a way to easily check all fields for changes between OLD and NEW?


delimiter //
CREATE TRIGGER check BEFORE UPDATE ON ???
FOR EACH ROW
BEGIN
    IF NEW.foo <> OLD.foo OR NEW.bar <> OLD.bar... THEN
        ???
    END IF;
END//
delimiter ;

It could work ^^

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜