Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

IF UPDATE (columnName) in update trigger

$
0
0

My understanding is that the Update trigger has a DELETED table and an INSERTED table, where the INSERTED table contains all the new data for the rows that were just modified, and the DELETED table contains all the original data for the rows that were just modified.  I'm creating a custom audit solution and want to write the original values from the deleted table to an audit table.  Also, I don't want to write all the data in the row, but want to write only the values that where modified.  Therefore I want to use the statement:

IF UPDATE (columnName)

    BEGIN

        // Write this value to the Audit table

    END

However, if there are multiple rows in the DELETED table, I'll need to use a cursor to loop through the rows.  additionally, if I'm looping through the rows, the IF UPDATE (columnName) logic probably will not be accurate.  I'm guessing the IF UPDATE statement would only apply to the first or last row in the deleted table.

Can anyone give me guidance on how to capture only the values that have been changed when there are multiple rows in the deleted table?

Thank you


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>