- 场景:数据库中一张表添加或更新数据时,通过触发器对另一张表进行添加或更新数据的操作。
- 使用:
begin declare num int; set num=(select count(*) from 表名 where BusinessId=new.Id and businessType=2 and Type=10); if num=0 then insert 表名(Id,Type,BusinessId,businessType,Status,Count,IsDeleted) values(uuid_short(),10,new.Id,2,2,1,1); else update 表名 set Count=0 where BusinessId=new.Id and businessType=2 and Type=10; end if; end
-
原文链接:https://blog.csdn.net/qq_15058425/article/details/72673788