MSSQL2005DML触发器种类的区分

在触发器中区分INSERT、UPDATE和DELETE,代码如下:

	DECLARE @isInsert bit,
		@isUpdate bit,
		@isDelete bit
	SET @isInsert = 0
	SET @isUpdate = 0
	SET @isDelete = 0
	
	IF EXISTS (SELECT 1 FROM INSERTED) AND EXISTS (SELECT 1 FROM DELETED) 
		SET @isUpdate = 1
	ELSE IF EXISTS (SELECT 1 FROM INSERTED)
		SET @isInsert = 1
	ELSE IF EXISTS (SELECT 1 FROM DELETED)
		SET @isDelete = 1

 

你可能感兴趣的:(sql2005)