经过触发器分发同步数据
发布时间:2022-03-27 21:15:22 所属栏目:MySql教程 来源:互联网
导读:通过触发器分发同步数据 create table tab(id int not null primary key,name varchar(20),age int,address varchar(200)); create table tab0(id int not null primary key,name varchar(20),age int,address varchar(200)); create table tab1(id int not
通过触发器分发同步数据 create table tab(id int not null primary key,name varchar(20),age int,address varchar(200)); create table tab0(id int not null primary key,name varchar(20),age int,address varchar(200)); create table tab1(id int not null primary key,name varchar(20),age int,address varchar(200)); create table tab2(id int not null primary key,name varchar(20),age int,address varchar(200)); delimiter // create trigger tri_sync_insert after insert on tab for each row begin declare v_result int; set v_result=mod(new.id,3); if v_result =0 then insert into tab0(id,name,age,address) values(new.id,new.name,new.age,new.address); elseif v_result = 1 then insert into tab1(id,name,age,address) values(new.id,new.name,new.age,new.address); else insert into tab2(id,name,age,address) values(new.id,new.name,new.age,new.address); end if; end; // delimiter ; ![]() delimiter // create trigger tri_sync_delete after delete on tab for each row begin declare v_result int; set v_result=mod(old.id,3); if v_result =0 then delete from tab0 where id=old.id; elseif v_result = 1 then delete from tab1 where id=old.id; else delete from tab2 where id=old.id; end if; end; // delimiter ; (编辑:晋中站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |