码迷,mamicode.com
首页 > 数据库 > 详细

MySql触发器实现数据同步学习

时间:2018-04-28 14:35:18      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:where   AC   tps   varchar   实现   new   logs   事件触发   log   

触发器实现:(增、删、改操作事件触发数据单向同步)
数据库触发器教程:https://www.cnblogs.com/phpper/p/7587031.html
同步代码:

DELIMITER $
DROP TRIGGER IF EXISTS insertdata;
CREATE TRIGGER insertdata AFTER INSERT ON repair.user FOR EACH ROW
BEGIN
DECLARE s1 INT(11);
DECLARE s2 VARCHAR(30);
SET s1=NEW.id;
SET s2=NEW.name;
INSERT INTO sale.user(id,name) VALUES(s1,s2);
END $

DELIMITER $
DROP TRIGGER IF EXISTS updatedata;
CREATE TRIGGER updatedata AFTER UPDATE ON repair.user FOR EACH ROW
BEGIN
DECLARE s1 INT(11);
DECLARE s2 VARCHAR(30);
SET s1=OLD.id;
SET s2=NEW.name;
UPDATE sale.user a SET a.name=s2 WHERE a.id=s1;
END $

DELIMITER $
DROP TRIGGER IF EXISTS deletedata;
CREATE TRIGGER deletedata AFTER DELETE ON repair.user FOR EACH ROW
BEGIN
DECLARE s1 INT(11);
DECLARE s2 VARCHAR(30);
SET s1=OLD.id;
SET s2=OLD.name;
DELETE FROM sale.user WHERE id=s1;
END $

 

MySql触发器实现数据同步学习

标签:where   AC   tps   varchar   实现   new   logs   事件触发   log   

原文地址:https://www.cnblogs.com/fuxuyang/p/8966483.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!