加入收藏 | 设为首页 | 会员中心 | 我要投稿 51站长网 (https://www.51zhanzhang.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
站内搜索:
当前位置: 首页 > 站长学院 > MySql教程 > 正文

经过触发器分发同步数据

发布时间:2022-03-26 12:39:10 所属栏目: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 ;

(编辑:ASP站长)

【免责声明】本站内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。

    相关内容
    未处理完善
      无相关信息
    未处理完善