views:

641

answers:

5

A DB Audit Trail captures the User Last Modified, Modified Date, and Created Date.

There are several possible implementations:

  • SQL Server Triggers
  • Add UserModified, ModifiedDate, CreatedDate columns to the database and include logic in Stored Procedures or Insert, Update statements accordingly.

It would be nice if you include implementation (or link to) in your answer.

+3  A: 

Depending on what you're doing, you might want to move the audit out of the data layer into the data access layer. It give you more control.

I asked a similar question wrt NHibernate and SqlServer here.

IainMH
+1  A: 

I totally second @IainMH (and voted him up).

You want to have it in your DAL and ideally tied to some kind of aspect/interceptor/code injection mechanism.

Alvaro Rodriguez
+1  A: 

+2 for implementation of when/how to audit in the DAL.

As for where the audit entries themselves should live, it depends on how it will be visible. I'd do a separate table if users can view a separate "audit trail report," but tag existing tables if you want to display last modified-type audits inline.

Aidan Ryan
+1  A: 

You might want to check out this article by Hibernate developer Christian Bauer.

binil
A: 

Here is the implementation I use to audit tables: Pop Rivett's SQL Server FAQ No.5: Pop on the Audit Trail

Gern Blandston