views:

83

answers:

4

There is a table in my database containing 100 columns. I want to create a trigger to audit the modification for every update operation.

What I can think is to create the update clause for all columns but they are all similar scripts. So is there any elegant way to do that?

+1  A: 

There's this resource on MSDN which you might find helpful:

Tracking Changes in the Server Database (including SQL Server 2008)

I'm not sure if you're using SQL Server 2008 though.

code4life
To be fair, the title didn't say that when code4life answered
Gareth
Not quite feasible.
sza
@sza could you elaborate? There are other resources that I didn't mention, perhaps these are a better fit...
code4life
A: 

Theoretically, you can use 1 trigger and check COLUMNS_UPDATED() to know which columns has changed. (not be tested) See more here

pinichi
+3  A: 

Check Change Data Capture

Update
CDC provides tracking of all details of changes. Available since SQL Server 2008.

More lightweight solution is Change Tracking (Sync Framework), the one code4life mentioned before, available since SQL Server 2005.

Update2:
Related questions (with a lot of sublinks):

vgv8
+1 best choice in SQL Server 2008 and up
marc_s
Requires Enterprise Edition.
Joe Stefanelli
Funny, I recall I've read that CDC requires EE but cannot find any reference. ChangeTracking is edition independent, correct?
vgv8
+1  A: 

Code generation?

Have you looked at the techniques which http://autoaudit.codeplex.com/ uses?

Cade Roux