我在删除/更新/插入操作时为表创建了一个触发器。
测试它是否是删除我使用此语句:
if exists(select * from deleted)
如果是插入内容:
if exists(select * from inserted)
但是如何测试它是否是更新
答案 0 :(得分:1)
SET @action = 'I'; -- Set Action to Insert by default.
IF EXISTS(SELECT * FROM DELETED)
BEGIN
SET @action =
CASE
WHEN EXISTS(SELECT * FROM INSERTED) THEN 'U' -- Set Action to Updated.
ELSE 'D' -- Set Action to Deleted.
END
END
ELSE
BEGIN
IF NOT EXISTS(SELECT * FROM INSERTED) -- New record inserted.
SET @action = 'I';
END