开发者

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

开发者 https://www.devze.com 2023-01-21 02:40 出处:网络
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.

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

精彩评论

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