SQL if update()语句用于触发器

时间:2012-06-07 15:42:41

标签: sql-server triggers

如果旧值不等于新值,我希望我的触发器仅在更新时执行。如果值保持不变,我不希望我执行块。

if UPDATE(interview)
    BEGIN 
    EXEC sp_send_dbmail
            @profile_name = 'SM_PRFL',
    @recipients = 'email',

    @subject = 'this is a test' ,
    @body = 'message'
            END

1 个答案:

答案 0 :(得分:0)

查看以下链接,查找“在INSTEAD OF触发器中使用插入和删除的表”:http://msdn.microsoft.com/en-us/library/ms191300(SQL.90).aspx

这应该允许您执行测试并根据需要执行操作。例如,你可以......

If ( Update(interview))
BEGIN
    -- If column esb has been changed from its previous value
    IF ((SELECT esb FROM INSERTED) <> select esb FROM DELETED)
    BEGIN
    EXEC sp_send_dbmail
            @profile_name = 'SM_PRFL',
    @recipients = 'email',

    @subject = 'this is a test' ,
    @body = 'message'
    END
END