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 ^^
精彩评论