Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
A Generic function in an UPDATE trigger to log changes
Message
From
10/08/2002 14:05:21
 
 
To
All
General information
Forum:
Microsoft SQL Server
Category:
Other
Title:
A Generic function in an UPDATE trigger to log changes
Miscellaneous
Thread ID:
00688341
Message ID:
00688341
Views:
71
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
Next
Reply
Map
View

Click here to load this message in the networking platform