Showing posts with label triggers. Show all posts
Showing posts with label triggers. Show all posts

Wednesday, March 28, 2012

Profile Vrs Triggers

Dear All,
Can anyone tell me for the purpose of auditing a database
what is better, putting in place a profile for a database,
or putting in triggers on database tables to capture
before and after changes ?
Thanks
PeterPeter,
Profiler is not intended to be run 24/7. It is a troubleshooting tool and sh
ould not be used for auditing (in my opinion). I prefer the trigger approach
, or even better, a stored procedure approach. If all your data access via a
n application is done via s
tored procedures, you can incorporate your audit code into the stored procs.
You can even write some t-sql to auto-generate your audit code for you. Bea
r in mind that using the stored proc approach will not capture changes made
outside of stored procedure
s.
It depends on the situation as to which method is best. A further point, you
do not need to capture the before and after data, just the "before", becaus
e the "after" change *is* the current data. In other words, just copy the ol
d values to an audit table
which would be a mirror of your audited table, with some extra columns to re
cord date/time, update/delete, who, etc.
Mark Allison, SQL Server MVP
http://www.markallison.co.uk