首页 > 代码库 > 触发器中判断操作是Insert还是Update还是Delete
触发器中判断操作是Insert还是Update还是Delete
在Sql Server触发器中判断操作是Insert还是Update还是Delete
DECLARE @IsInsert bit, @IsUpdate bit, @IsDelete bitIF EXISTS(SELECT 1 FROM inserted) AND NOT EXISTS(SELECT 1 FROM deleted) SET @IsInsert = 1ELSE SET @IsInsert = 0IF EXISTS(SELECT 1 FROM inserted) AND EXISTS(SELECT 1 FROM deleted) SET @IsUpdate = 1ELSE SET @IsUpdate = 0IF NOT EXISTS(SELECT 1 FROM inserted) AND EXISTS(SELECT 1 FROM deleted) SET @IsDelete = 1ELSE 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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。