Hi, all...
In my UPDATE trigger, I'd like to be able to write every DB change to an application log.
I know that in my UPDATE trigger, I can do a...
SELECT * FROM INSERTED
SELECT * FROM DELETED
And then do a ...
DECLARE @Field1_OldValue Char(20)
DECLARE @Field1_NewValue Char(20)
set @Field1_NewValue = (select field1 from inserted)
set @Field1_OldValue = (select field1 from deleted)
if @field1_NewValue <> @field1_OldValue
' write out to application log that 'field1' changed from 'old value' to 'new value' on
by user
The 'problem' is that I have to write this for every field...and I have five other tables where I'd like to apply this. Can I write some type of generic loop to do this?
I've also looked at columns_updated, but that has me even more confused about ways to make it generic.
Obviously, typing code to check for each field 'works', but I have to believe there's a more elegant way.
Any ideas?
Thanks,
Kevin