首页 > 其他 > 详细

触发器中判断操作是Insert还是Update还是Delete

时间:2014-08-16 18:20:40      阅读:333      评论:0      收藏:0      [点我收藏+]

在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 

 

触发器中判断操作是Insert还是Update还是Delete,布布扣,bubuko.com

触发器中判断操作是Insert还是Update还是Delete

原文:http://www.cnblogs.com/karsase/p/3916609.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!