SQL Server Nation
For all of your SQL Server needs.

Audit Trail - some columns and the corresponding column's old vale and new value

rated by 0 users
Not Answered This post has 0 verified answers | 3 Replies | 2 Followers

Resh posted on 28 Jan 2010 5:23 AM

Hi Team,

I would like to create an audit trail for a particular table  with column name and the old value and the new value whenever some of the columns in the main table are being updated. I need to audit trail only a few columns. Is there an easy way to do this?

 

Audit_Trial ID

Table Name

Old Value

New Value

Updated StaffCode

Updated Time

 

 

 

 

 

 

Please see below the structure I'm planning to implement.

 

 

Any help would be much appreciated.

Many Thanks,

 

All Replies

The most reliable way to perform this is via a trigger.  What version/edition of SQL Server are you using?

Co-Founder
SQL Server MVP
BrandonGalderisi
SQL Server Nation

Thanks for your response BrandonGalderisi. I'm using SQL 2005.

Is there a way we can make it as a stored proc? Trigger has some disadvantages like it won't support 'Text'. Also if somebody do a back end modification, those information will also be stored in the Audit Trail table if I'm using Trigger.

 

Well if you are doing a true audit trail, then you want it to include modifications made through the backend.  That is the benefit to using a trigger.

If you  want it to be in stored procedures, then you should modify any and all stored procedures that update the tables which you want to audit.  There is no way to do a generic procedure without it being very... well... hacky.

Co-Founder
SQL Server MVP
BrandonGalderisi
SQL Server Nation

Page 1 of 1 (4 items) | RSS
Copyright SQL Server Nation 2010
Powered by Community Server (Non-Commercial Edition), by Telligent Systems