0

当执行删除/更新/插入操作时,我为表创建了触发器。

要测试它是否是删除,我使用以下语句:

if exists(select * from deleted)

如果它是一个插入:

if exists(select * from inserted)

但是我如何测试它是否是更新

4

1 回答 1

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
于 2013-03-06T09:42:54.460 回答