Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
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: 4414 | Views in the last 30 days: 9
Related Articles

Insert trigger not working when update trigger enabled

Update interfering with insert trigger.


Triggers for Auditing

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


Trigger defined for Insert, Update

Determine Update or Insert for Trigger defined for Insert, Update


update trigger not updating across databases

update trigger not updating across databases



Triggers for audit


Join the most active online SQL Server Community

SQL knowledge, delivered daily, free:

Email address:  

You make SSC a better place

As a member of SQLServerCentral, you get free access to loads of fresh content: thousands of articles and SQL scripts, a library of free eBooks, a weekly database news roundup, a great Q & A platform… And it’s our huge, buzzing community of SQL Server Professionals that makes it such a success.

Join us!

Steve Jones

Already a member? Jump in:

Email address:   Password:   Remember me: Forgotten your password?
Steve Jones