Click here to Skip to main content
15,888,201 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
What is the proper way for implementing audit triggers. I found many examples but I am still not sure what is the best way to implement. I need to track changes on few tables. Basically I need to keep track of everything. I want it nice and clean.
Posted
Comments
gvprabu 26-Apr-13 3:55am    
you have to track only table changes (DDL) or DML things also.
If any other object s like SP, Functions, views also u need to track the changes.

Refer this link to understand how to implement[Audit Trail].
 
Share this answer
 
The "proper" way to make triggers really depends on your database schema, your application, your need to audit etc etc .... for example *we* currently audit approximately 150 "sensitive" items across 20 tables ... we don't "care" about the rest.

This link has discussions about several potential solutions http://stackoverflow.com/questions/1962398/creating-audit-triggers-in-sql-server[^]

When you say you need to track "everything" do you mean update, deletions, insertions ... (answer should probably be yes to the last two)... when you "audit" an update ... do you actually need to know what was updated or just the fact that the record was updated.
When you have defined clearly what your requirements are only then can you really determine the "proper" way.

An alternative that has been used by certain solution providers is to have columns on each table that show when they were created (and who by) and when they were last updated (and who by) ... this is very simply implemented using table triggers without having to purchase 3rd party tools ... and also simplifies the subsequent detailed audit requirements
 
Share this answer
 
If you just need to make triggers for a few tables I suggest installing some tool like ApexSQL Audit[^] Use it in trial mode to make audit triggers and then examine how it is done. Than just make your triggers. Nice and clean :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900