标签:mysql 触发器
-- 新增 create trigger YQHL_HTJS_B_HTJBXX_INSERT before insert on 表名 for each row begin if (NEW.F_SYNC_UPDATE is null) or (NEW.F_SYNC_UPDATE = 0) then set NEW.F_SYNC_UPDATE=null; -- 把新增加的记录插入到操作记录表 insert into DATA_SYNC_B_OPERATOR(t_name, o_type, o_date, VKEYS) values(‘表名‘,1, CURRENT_TIMESTAMP,NEW.HTDQBH); end if; end; -- 修改 create trigger YQHL_HTJS_B_HTJBXX_UPDATE before update on 表名 for each row begin if (NEW.F_SYNC_UPDATE is null) or (NEW.F_SYNC_UPDATE = 0) then -- 插入和更新操作,更新时间戳F_SYNC_DATE=systimestamp和F_SYNC_UPDATE=null set NEW.F_SYNC_UPDATE=null; end if; end; -- 删除 create trigger YQHL_HTJS_B_HTJBXX_DELETE before delete on 表名 for each row begin if (OLD.F_SYNC_UPDATE is null) or (OLD.F_SYNC_UPDATE = 0) then -- 插入和更新操作,更新时间戳F_SYNC_DATE=systimestamp和F_SYNC_UPDATE=null -- 把删除记录的主键添加到操作记录表 insert into DATA_SYNC_B_OPERATOR(t_name, o_type, o_date, VKEYS) values(‘表名‘,3, CURRENT_TIMESTAMP,OLD.HTDQBH); end if; end;
本文出自 “随便写写” 博客,请务必保留此出处http://7156680.blog.51cto.com/7146680/1790835
标签:mysql 触发器
原文地址:http://7156680.blog.51cto.com/7146680/1790835