Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
A Generic function in an UPDATE trigger to log changes
Message
De
10/08/2002 14:05:21
 
 
À
Tous
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Titre:
A Generic function in an UPDATE trigger to log changes
Divers
Thread ID:
00688341
Message ID:
00688341
Vues:
70
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
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform