加入收藏 | 设为首页 | 会员中心 | 我要投稿 河北网 (https://www.hebeiwang.cn/)- 数据治理、智能边缘、专属主机、云容器引擎、云备份!
当前位置: 首页 > 编程 > 正文

触发器分发同步数据

发布时间:2023-12-21 01:28:50 所属栏目:编程 来源:DaWei
导读: 通过触发器分发同步数据

create table tab(id int not null primary key,name varchar(20),age int,address varchar(200));
create table tab0(id int not nul
      通过触发器分发同步数据
  
     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 ;

(编辑:河北网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章