在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
@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