Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

A Simply way to implement Audit Trail in SQL 2005

By huang_xiaodi,

In a recent project, I need to record audit trail for some tables (for Insert, Update and Delete).
Using SQL 2005's XML datatype and the XML support it is very covenienet to use triggers to perform the audit trail requirement.
I create one table (Table_Audit)  to hold all audit trial data.
One stored procedure is created to generate the triggers for desired table.
The syntax to call the stored procedure is: EXEC dbo.USPU_Generate_Audit_Trigger ( 'tablename').
The trigger will do all the Audit work for you then.
If you need to deal with existing triggers, you may have to use sp_settriggerorder to set the execution order for those triggers and let the audit trigger fired last.

Author: Bill Huang
Company: Neurocomp Systems, Inc.
Date Submited: 09/20/2007

Total article views: 3244 | Views in the last 30 days: 7
 
Related Articles
FORUM

Audit

Triggers for audit

ARTICLE

Auditing Through Triggers

In this article by Robert Marda, he shows you how to setup a simple auditing system through triggers...

ARTICLE

Triggers for Auditing

Have you ever needed to audit your SQL Server 2000 database for changes to a table? A simple auditin...

SCRIPT

Script Generates Audit Triggers

This script generates a audit trigger for each table in the database. The trigger then logs when eac...

FORUM
Tags
 
Contribute

Join the most active online SQL Server Community

SQL knowledge, delivered daily, free:

Email address:  

You make SSC a better place

As a member of SQLServerCentral, you get free access to loads of fresh content: thousands of articles and SQL scripts, a library of free eBooks, a weekly database news roundup, a great Q & A platform… And it’s our huge, buzzing community of SQL Server Professionals that makes it such a success.

Join us!

Steve Jones
Editor, SQLServerCentral.com

Already a member? Jump in:

Email address:   Password:   Remember me: Forgotten your password?
Steve Jones