Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Can you set off a trigger based on one column changing?
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2008
Miscellaneous
Thread ID:
01466971
Message ID:
01466973
Views:
76
I am wondering how you would set off a trigger based on only one column changing? Is this possible? I know you can set a trigger to run if there has been a delete, update or insert based on the table, but how would you narrow this down to one column having changed?

With triggers, I don't believe you can.

Closest you can do is the following....suppose you want to detect if ProductMaster.ListPrice has changed...
DECLARE @NumRowsChangedByUpdate int

SET @NumRowsChangedByUpdate = 
    (select  Count(ProductMaster.ProductKey) from ProductMaster
                                         JOIN Inserted on ProductMaster.ProductKey = Inserted.ProductKey
                                         join Deleted on ProductMaster.ProductKey = Deleted.ProductKey
                                                where Inserted.ListPrice <> Deleted.ListPrice)

if @NumRowsChangedByUpdate > 0
          -- then go do something
However, if you're using Change Data Capture, you could theoretically tap into something using CDC if you set it up for just a single column, though it's going to involve some work.

What specifically do you want to do when the single column value changes?
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform