SQL Clone
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)

Script Generates Audit Triggers

By Farrell Thomas,

As a DBA , I had to determine if a large number of Databases were actually being used. I wrote this script to create triggers that write to an audit table if any table in the Database was updated.

It first creates an audit table to write to whenever any table is updated.

It then loops thru each table and generates an Insert,Update and Delete trigger for each table.

Whenever a row in any table is updated,inserted, or deleted it inserts a row to the audit table with the date of the update.

It will only log the update once, since the purpose of this was to determine if the Database was being used.

I checked the audit table after about 3 months, and removed any Databases that showed no update activity.

Of course if the Database is not being updated, this will not work. However most tables in a Database will eventually be updated, then the trigger will capture the date of the update.

Total article views: 4524 | Views in the last 30 days: 1
Related Articles

Insert trigger not working when update trigger enabled

Update interfering with insert trigger.


Trigger defined for Insert, Update

Determine Update or Insert for Trigger defined for Insert, Update


Triggers for Auditing

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


update trigger not updating across databases

update trigger not updating across databases



Triggers for audit