首页 >
数据库 >
mysql
mysql表同步触发器
时间:2019-03-21 16:32:59 点击: 来源: 作者:
同一库内的两个表,触发器同步:
#增加
delimiter ||
DROP TRIGGER IF EXISTS t_afterinsert_on_tab1 ||
CREATE TRIGGER t_afterinsert_on_tab1
AFTER INSERT ON test1
FOR EACH ROW
BEGIN
insert into test2 ...
同一库内的两个表,触发器同步:
#增加
delimiter ||
DROP TRIGGER IF EXISTS t_afterinsert_on_tab1 ||
CREATE TRIGGER t_afterinsert_on_tab1
AFTER INSERT ON test1
FOR EACH ROW
BEGIN
insert into test2(id,name,phone) values(new.id,new.name,new.phone);
END||
delimiter ;
#删除
delimiter ||
DROP TRIGGER IF EXISTS t_afterdelete_on_tab1||
CREATE TRIGGER t_afterdelete_on_tab1
AFTER DELETE ON test1
FOR EACH ROW
BEGIN
delete from test2 where id=old.id;
END||
#修改
DELIMITER $
CREATE TRIGGER t_afterupdate_on_tab1
AFTER UPDATE ON test1
FOR EACH ROW
BEGIN
UPDATE test2
SET id = new.id,
name=new.name,
参考:
https://www.duyunwl.cn/2019/03/15/mysql%E8%A1%A8%E5%90%8C%E6%AD%A5/?tdsourcetag=s_pcqq_aiomsg
”您可通过以下微信二维码,赞赏作者“