有两张备注A和B,允许往A里面弹出一条记录的同时要向B里面也接在一条记录,向B里面插进一条记录的同时也向A插进一条记录。两张表的结构有所不同,并不需要将其中几个字段对应上来。可以用下面的触发器借助于。
同上A的触发器:
beginset @disable=1;if @disable=1 and NOT EXISTS(SELECT 1 FROM tableB where ID=new.ID) then insert into tableB (ID,对应字段1) values(new.ID,new.对应字段1);end if; set @disable=0;end
备注B的触发器:
beginset @disable=1;if @disable=1 and NOT EXISTS(SELECT 1 FROM tableA where ID=new.ID) then insert into tableA (ID,对应字段1) values(new.ID,new.对应字段1);end if; set @disable=0;end