locked
How to track only one column updated in SQL Server 2012? RRS feed

  • Question

  • Is there a way to only track one specific column named Newsletter (bit format) of a table only when any record in that column has been changed from False to True?

    e.g. In SQL Serer 2012, I have a table named tblSignupHistory. so i originally set the query like this:

    ALTER TABLE tblSignupHistory
    ENABLE CHANGE_TRACKING
    WITH(TRACK_COLUMNS_UPDATED = ON)

    and in my stored procedure, if any data is changed, SQL Server will automatically send me an email notification.

    BUT i only want the notification email to be send only when this one specific column's value is changed from 0 to 1 (False to True). Any changes in other columns for the same table can be ignored.

    Thanks.

    Wednesday, April 9, 2014 5:01 PM

Answers

  • You can do it inside trigger using UPDATE() function if its a single column or COLUMNS_UPDATED function if you want to track multiple columns

    In CDC you use $update_mask for that

    see 

    http://sqljudo.wordpress.com/2013/11/03/sql-server-cdc-lessons-learned/


    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

    • Proposed as answer by Fanny Liu Thursday, April 10, 2014 9:59 AM
    • Marked as answer by Fanny Liu Sunday, April 20, 2014 4:52 AM
    Wednesday, April 9, 2014 5:22 PM

All replies