Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
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: 3278 | Views in the last 30 days: 2
 
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