Suggestions for implementing audit tables in SQL Server? Suggestions for implementing audit tables in SQL Server? sql-server sql-server

Suggestions for implementing audit tables in SQL Server?


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.


We are using two table design for this.

One table is holding data about transaction (database, table name, schema, column, application that triggered transaction, host name for login that started transaction, date, number of affected rows and couple more).

Second table is only used to store data changes so that we can undo changes if needed and report on old/new values.

Another option is to use a third party tool for this such as ApexSQL Audit or Change Data Capture feature in SQL Server.


I have found these two links useful:

Using CLR and single audit table.
Creating a generic audit trigger with SQL 2005 CLR

Using triggers and separate audit table for each table being audited.
How do I audit changes to SQL Server data?