![]() |
Database »
Database »
SQL Server
Intermediate
CodeSmith generated Audit Log TriggersBy RichardRoeCodeSmith template for creating Audit Log Triggers on SQL tables. |
C++, SQL, Windows, Visual Studio, SQL 2000, SQL 2005, DBA, Dev
|
|
Advanced Search |
|
|
|
||||||||||||||||
I don't think its necessary for me to sing the praises of CodeSmith. Go to the link and try it out if you haven't.
I needed to keep an Audit Log of changes made to SQL Server tables, but I'd already written the application so I needed a quick and easy solution that didn't require a whole new set of Unit and System testing of my application. I knew CodeSmith had some templates that generated SQL scripts and allowed developers to create there own scripts without having to write hundreds of lines of code. The result is the AuditTriggers CodeSmith template.
Once you've installed CodeSmith, you can run the script on your SQL Server database tables that you need Audit Logs for. It will generate a SQL script that you can install on the database or modify and install.
If you look in the comments of the generated script, you will see the Create Table script.
-- Audit Table looks like this
-- CREATE TABLE [dbo].[<%= AuditTableName %>] (
-- [ChangeLogID] [int] IDENTITY (1, 1) ,
-- [OperationType] [varchar] (10) NOT NULL ,
-- [ChangeTimestamp] [datetime] NOT NULL ,
-- [MadeBy] [varchar] (6) NOT NULL ,
-- [TableChanged] [varchar] (50) NOT NULL
-- ) ON [PRIMARY]
-- Detail Table looks like this
-- CREATE TABLE [dbo].[<%= AuditFieldTableName %>] (
-- [FieldName] [varchar] (50) NOT NULL ,
-- [ChangeLogID] [int] NOT NULL ,
-- [sql_variant] NOT NULL ,
-- [AfterValue] [sql_variant] NOT NULL
-- ) ON [PRIMARY]
The above script is the Log tables where all the audit logs will be inserted. Note: The AuditTrigger script doesn't generate Audit Logs for BLOB data types.
For a quick and easy solution for any type of code, CodeSmith is up there with the best of them.
| You must Sign In to use this message board. | |||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 7 Apr 2005 Editor: Smitha Vijayan |
Copyright 2005 by RichardRoe Everything else Copyright © CodeProject, 1999-2009 Web16 | Advertise on the Code Project |