refer from : Using MySQL Triggers to Audit Field Changes from a Database Table
我要更新一下我的使用情況為如果變更的content欄位前後有變動才要觸發update的動作:
DELIMITER |
CREATE TRIGGER audit_content BEFORE UPDATE ON conten
FOR EACH ROW BEGIN
IF OLD.content <> NEW.content THEN
INSERT INTO content_audit SET content_id = OLD.id,before_value = OLD.cont
ent,after_value = NEW.content;
END IF;
END;
|
太帥了,有了這個功能,我的工作可以繼續了。