博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
MySql 触发器同步备份数据表记录
阅读量:6720 次
发布时间:2019-06-25

本文共 2594 字,大约阅读时间需要 8 分钟。

 

添加记录到新记录表

DELIMITER $$USE `DB_Test`$$CREATE    /*!50017 DEFINER = 'root'@'%' */    TRIGGER `InsertOPM_Alarm_trigger` BEFORE INSERT ON `OPM_Alarm`     FOR EACH ROW BEGININSERT INTO OPM_Alarm_copy (AlarmId,AlarmCode,AlarmTypeId,AlarmLevelId,AlarmObjectCode,AlarmStatus,AlarmHandleUser,AlarmHandleTime,ADDTIME,ParkUserId,BerthCode,BargainOrderCode,BerthStartTime)VALUES(new.AlarmId,new.AlarmCode,new.AlarmTypeId,new.AlarmLevelId,new.AlarmObjectCode,new.AlarmStatus,new.AlarmHandleUser,new.AlarmHandleTime,new.ADDTIME,new.ParkUserId,new.BerthCode,new.BargainOrderCode,new.BerthStartTime);    END;$$DELIMITER ;
CREATE  TRIGGER InsertOPM_Alarm_trigger   BEFORE  INSERT  ON OPM_Alarm  FOR  EACH ROWBEGIN INSERT INTO OPM_Alarm_copy (AlarmId,AlarmCode,AlarmTypeId,AlarmLevelId,AlarmObjectCode,AlarmStatus,AlarmHandleUser,AlarmHandleTime,ADDTIME,ParkUserId,BerthCode,BargainOrderCode,BerthStartTime)VALUES(new.AlarmId,new.AlarmCode,new.AlarmTypeId,new.AlarmLevelId,new.AlarmObjectCode,new.AlarmStatus,new.AlarmHandleUser,new.AlarmHandleTime,new.ADDTIME,new.ParkUserId,new.BerthCode,new.BargainOrderCode,new.BerthStartTime);END ;

 mysql触发器监控mysql数据表记录删除操作 

DELIMITER $$USE `DB_Test`$$DROP TRIGGER /*!50032 IF EXISTS */ `SYS_OPM_trigger`$$CREATE    /*!50017 DEFINER = 'root'@'%' */    TRIGGER `SYS_OPM_trigger` AFTER DELETE ON `OPM_Alarm`     FOR EACH ROW BEGIN    DECLARE str VARCHAR(40000);      SET str=CONCAT(old.AlarmId,'@',old.AlarmCode,'@',old.AlarmTypeId,'@',old.AlarmLevelId,'@',      old.AlarmObjectCode,'@',old.AlarmStatus,'@',old.AlarmHandleUser,'@',old.AlarmHandleTime,'@',      old.AddTime,'@',old.ParkUserId,'@',old.BerthCode,'@',old.BargainOrderCode,'@',old.BerthStartTime);      INSERT INTO OPM_AlarmAction_log(UserName,Client_IP,Delete_before_key,Delete_Date)     VALUES(SUBSTRING_INDEX(USER(),'@',1),SUBSTRING_INDEX(USER(),'@',-1), str, NOW());    END;$$DELIMITER ;

删除前 添加原记录备份到另一记录表

DELIMITER $$USE `DB_Test`$$DROP TRIGGER /*!50032 IF EXISTS */ `InsertOPM_Alarm_trigger`$$CREATE    /*!50017 DEFINER = 'root'@'%' */    TRIGGER `InsertOPM_Alarm_trigger` BEFORE DELETE ON `OPM_Alarm`     FOR EACH ROW BEGIN     INSERT INTO OPM_Alarm_copy (AlarmId,AlarmCode,AlarmTypeId,AlarmLevelId,AlarmObjectCode,AlarmStatus,AlarmHandleUser,        AlarmHandleTime,ADDTIME,ParkUserId,BerthCode,BargainOrderCode,BerthStartTime)         VALUES(old.AlarmId,old.AlarmCode,old.AlarmTypeId,old.AlarmLevelId,old.AlarmObjectCode,old.AlarmStatus,old.AlarmHandleUser,                 old.AlarmHandleTime,old.ADDTIME,old.ParkUserId,old.BerthCode,old.BargainOrderCode,old.BerthStartTime);             END;$$DELIMITER ;

 

转载地址:http://abcmo.baihongyu.com/

你可能感兴趣的文章
Mysql left join,right join,inner join的效率比较
查看>>
SpringMVC的返回视图几种方式
查看>>
lvs+keepalived实现实时监控节点健康状态,并根据算法接管资源
查看>>
JavaScript之基础-12 JavaScript 错误处理
查看>>
SaltStack源码分析之group状态模块
查看>>
SVN备份方案
查看>>
linux下实现ssh授权、无密码登录
查看>>
exchange server 2003 错误处理 事件ID2050
查看>>
nodejs中npm常用命令
查看>>
Java忽略大小写替换和提取字符信息
查看>>
面试题
查看>>
C++中拷贝构造函数
查看>>
Struts2 分发
查看>>
关于PHP CGI和CLI的几点学习
查看>>
mysql 主从
查看>>
【OSC手机App技术解析】- 富文本列表的展示
查看>>
Understanding How to Read a Userenv Log – Part 2
查看>>
Linux Bash脚本练习3
查看>>
80、交换机配置实验之Remote SPAN
查看>>
100的奇数
查看>>