建立一个触发器,当表执行insert 操作时,进行下面操作,当执行update时,进行另一种操作。求例子
1个回答
2013-12-11
展开全部
DECLARE
@IsInsert bit,
@IsUpdate bit,
@IsDelete bitIF EXISTS(SELECT 1 FROM inserted) AND NOT EXISTS(SELECT 1 FROM deleted)
SET @IsInsert = 1
ELSE
SET @IsInsert = 0IF EXISTS(SELECT 1 FROM inserted) AND EXISTS(SELECT 1 FROM deleted)
SET @IsUpdate = 1
ELSE
SET @IsUpdate = 0IF 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
@IsInsert bit,
@IsUpdate bit,
@IsDelete bitIF EXISTS(SELECT 1 FROM inserted) AND NOT EXISTS(SELECT 1 FROM deleted)
SET @IsInsert = 1
ELSE
SET @IsInsert = 0IF EXISTS(SELECT 1 FROM inserted) AND EXISTS(SELECT 1 FROM deleted)
SET @IsUpdate = 1
ELSE
SET @IsUpdate = 0IF 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
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |