zoukankan      html  css  js  c++  java
  • 触发器实例

    前提有总表分表
    --
    ------------------------------------------------------------------------------------------------------------------------------------ insert 触发器 create trigger insert_trigger after insert on blog for each row begin if new.userid % 3 = 0 then insert into blog_0(id,title,content,userid,pubtime) value(new.id,new.title,new.content,new.userid,new.pubtime); elseif new.userid % 3 = 1 then insert into blog_1(id,title,content,userid,pubtime) value(new.id,new.title,new.content,new.userid,new.pubtime); elseif new.userid % 3 = 2 then insert into blog_2(id,title,content,userid,pubtime) value(new.id,new.title,new.content,new.userid,new.pubtime); end if; end// insert into blog(id,title,content,userid,pubtime) value('111','134','789','456','123'); -------------------------------------------------------------------------------------------------------------------------------------- delete 触发器 create trigger delete_trigger after delete on blog for each row begin if old.userid % 3 = 0 then delete from blog_0 where id=old.id; elseif old.userid % 3 = 1 then delete from blog_1 where id=old.id; elseif old.userid % 3 = 2 then delete from blog_2 where id=old.id; end if; end// delete from blog where id = 111; -------------------------------------------------------------------------------------------------------------------------------------- update 触发器 create trigger update_trigger after update on blog for each row begin if old.userid % 3 = 0 then update blog_0 set title = new.title, content=new.content where id=old.id; elseif old.userid % 3 = 1 then update blog_1 set title = new.title, content=new.content where id=old.id; elseif old.userid % 3 = 2 then update blog_2 set title = new.title, content=new.content where id=old.id; end if; end// update blog set title="abc",content="ccc" where id= 112//
  • 相关阅读:
    2019年春季学期第三周作业
    2019春第二周作业+一些的挑战作业
    查找整数
    寒假作业3编辑总结
    寒假作业2编辑总结
    对自己影响最大的老师
    2019春第九周作业
    2019春第八周作业
    2019春第七周作业
    2019春第六周作业
  • 原文地址:https://www.cnblogs.com/chenliuxiao/p/9327900.html
Copyright © 2011-2022 走看看