Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How you get a list of updated columns in SQL server trigger?

I want to know what columns where updated during update operation on a triger on first scaaning books online it looks like COLUMNS_UPDATED is the perfect solution but this function actualy don't check if values has changed , it check only what columns where selected in update clause, any one has other suggestions ?

like image 508
MichaelT Avatar asked May 27 '09 13:05

MichaelT


2 Answers

We can use Update function to find if a particular column is updated:

IF UPDATE(ColumnName)

Refer to this link for details: http://msdn.microsoft.com/en-us/library/ms187326.aspx

like image 116
Anuradha Avatar answered Oct 07 '22 04:10

Anuradha


The only way you can check if the values have changed is to compare the values in the DELETED and INSERTED virtual tables within the trigger. SQL doesn't check the existing value before updating to the new one, it will happily write a new identical value over the top - in other words, it takes your word for the update and tracks the update rather than actual changes.

like image 26
David M Avatar answered Oct 07 '22 03:10

David M