简体   繁体   English

在列上的T SQL After Update Trigger之后获取更改的值

[英]T SQL After Update Trigger on column get the value changed

I've only started exploring with triggers recently. 我最近才开始使用触发器进行探索。 I've set up my database mail function and all is working well. 我已经设置了数据库邮件功能,并且一切正常。 My trigger works perfectly if the column value is changed, but how do I get the value/row that changed? 如果更改了列值,我的触发器就可以正常工作,但是如何获得更改后的值/行?

USE [database]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER TRIGGER [dbo].[triggerName] ON [dbo].[tableName]
FOR UPDATE
AS

declare @cust varchar(100);


    if update(Column)
    BEGIN
    SET NOCOUNT ON
        set @cust = THE VALUE MUST GO HERE I ASSUME
    END
    EXEC msdb.dbo.sp_send_dbmail
    @recipients = 'someone@example.com', 
    @profile_name = 'ProfileName',
    @subject = 'Customer Information Changed', 
    @body = @cust;

Compare the values in inserted and deleted . 比较inserteddeleted的值。 If they are not the same, then the value changed. 如果它们不相同,则值会更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM