不具参考价值--Mysql设置外键及触发器约束问题

来源:互联网 发布:刘姓取名知乎 编辑:程序博客网 时间:2024/06/05 21:57

    Mysql设置外键不成功,不止我很多同学也没成功。

    于是又想通过添加触发器约束来替代外键功能,

before insert on tb_clct
for each row
begin
     set @a = (select count(*) from tb_clct where new.jid = id);
     if @a<1 then delete from tb_clct where id=-1;
     end if;
end;

//在tb_clct上面设置更新触发器,检查tb_journal的id
create trigger beforeupdate_tb_clct
before update on tb_clct
for each row
begin
      set @a = (select count(*) from tb_clct where new.jid = id);
     if @a<1 then delete from tb_clct where id=-1;
     end if;
end

//在tb_journal上设置更新触发器
create trigger afterupdate_tb_clct
after update on tb_journal
for each row
begin
     update tb_clct set jid=new.id from tb_journal,tb_clct where jid = old.id;
end;  


貌似最后是更新触发器没设置成功

原创粉丝点击