在Sql Server触发器中判断操作是Insert还是Update还是Delete
Posted jijm123
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在Sql Server触发器中判断操作是Insert还是Update还是Delete相关的知识,希望对你有一定的参考价值。
DECLARE @IsInsert bit, @IsUpdate bit, @IsDelete bit IF EXISTS(SELECT 1 FROM inserted) AND NOT EXISTS(SELECT 1 FROM deleted) SET @IsInsert = 1 ELSE SET @IsInsert = 0 IF EXISTS(SELECT 1 FROM inserted) AND EXISTS(SELECT 1 FROM deleted) SET @IsUpdate = 1 ELSE SET @IsUpdate = 0 IF NOT EXISTS(SELECT 1 FROM inserted) AND EXISTS(SELECT 1 FROM deleted) SET @IsDelete = 1 ELSE SET @IsDelete = 0 create trigger Update_Del on Table for update,delete as if not exists(select 1 from inserted) begin /*inserted表无记录,是删除*/ end else begin /*是更新*/ end go ---------------------
以上是关于在Sql Server触发器中判断操作是Insert还是Update还是Delete的主要内容,如果未能解决你的问题,请参考以下文章
SQL SERVER 分页查询 和 Inser 添加并返回Id