views:

1815

answers:

7

One simple method I've used in the past is basically just creating a second table whose structure mirrors the one I want to audit, and then create an update/delete trigger on the main table. Before a record is updated/deleted, the current state is saved to the audit table via the trigger.

While effective, the data in the audit table is not the most useful or simple to report off of. I'm wondering if anyone has a better method for auditing data changes?

+1  A: 

Are there any built-in audit packages? Oracle has a nice package, which will even send audit changes off to a separate server outside the access of any bad guy who is modifying the SQL.

Their example is awesome... it shows how to alert on anybody modifying the audit tables.

Mark Harrison
+5  A: 

How much writing vs. reading of this table(s) do you expect?

I've used a single audit table, with columns for Table, Column, OldValue, NewValue, User, and ChangeDateTime - generic enough to work with any other changes in the DB, and while a LOT of data got written to that table, reports on that data were sparse enough that they could be run at low-use periods of the day.

Added: If the amount of data vs. reporting is a concern, the audit table could be replicated to a read-only database server, allowing you to run reports whenever necessary without bogging down the master server from doing their work.

Greg Hurlman
A: 

@Greg - there shouldn't be too many updates of these records, but it is highly sensitive information, so it is important to the customer that all changes are audited and easily reported on.

bcwood
+1  A: 

OmniAudit might be a good solution for you need. I've never used it before because I'm quite happy writing my own audit routines, but it sounds good.

GateKiller
+1  A: 

I use the approach described by Greg in his answer and populate the audit table with a stored procedure called from the table triggers.

Chris Miller
+4  A: 

SQL Server 2008 has some built-in support with the new Change Data Capture feature

http://msdn.microsoft.com/en-us/library/bb522489.aspx

andyp
I should point out that this feature is only available in the Enterprise edition.
+1  A: 

I have found these two links useful:

Using CLR and single audit table.
http://www.sqljunkies.ddj.com/Article/4CD01686-5178-490C-A90A-5AEEF5E35915.scuk

Using triggers and separate audit table for each table being audited.
http://sqlserver2000.databases.aspfaq.com/how-do-i-audit-changes-to-sql-server-data.html

HadleyHope