Hello all,
I have an after trigger implemented in SQLCLR assembly. Within it I'd like to know, what columns have been really updated (and their values have been changed).
Unfortunately, SqlContext.TriggerContext.IsUpdatedColumn returns true, even when a column value is still the same. I guess, it's just because an SQL query, prepared by a not-very-smart server application, rewrites all columns, even if some of them have not been changed by user.
The second problem is some of the columns have ntext type, so I cannot even SELECT them from INSERTED pseudo table (MS SQL Server doesn't allow SELECT fields which have ntext type from INSERTED). That's why now I SELECT changed rows with the following query:
SELECT * FROM [dbo].[MyTable] WHERE [id] IN (SELECT [id] FROM INSERTED)
What should I do to get to know, what columns are not just updated, but changed?
Now I have a simple idea: create another trigger, BEFORE, and save updated rows from within. Then, when AFTER trigger is being executed, compare column values. Is this idea the best thing I can do? If so, what is the best place to keep the changed rows between BEFORE and AFTER triggers? A temporary table will be dropped before the AFTER trigger is executed, since I close context connection (maybe, just don't close?).