首页 > 数据库 > mysql > 正文

mysql表同步触发器
2019-03-21 16:32:59   来源:   评论:0 点击: 收藏

同一库内的两个表,触发器同步 增加delimiter ||DROP TRIGGER IF EXISTS t_afterinsert_on_tab1 ||CREATE TRIGGER t_afterinsert_o
同一库内的两个表,触发器同步:



#增加
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


相关热词搜索:

上一篇:mysql 导入数据出错 Invalid default value
下一篇:最后一页