SQL Server Central is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
Search:  
 
 

Script Generates Audit Triggers

By Farrell Thomas, 2008/06/12

Total article views: 6 | Views in the last 30 days: 6

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.

By Farrell Thomas, 2008/06/12

Total article views: 6 | Views in the last 30 days: 6
Your response
 
 
Related tags

Audit    
Database being used    
trigger    
 
Related content

Audit SQL Logins - Updated

By Derrick H. | Category: Audit
| 6,670 reads

Table journal

By Boka | Category: journal
(not yet rated) | 737 reads
Already registered?  

Free registration required

To read the rest of this article, and access thousands of other articles, we ask you to register on the site and subscribe to our newsletters.

Register

E-mail address:
Password:
Password (confirm):

  

Subscriptions

We ask you to register on the site and subscribe to our newsletters. Subscribing to our newsletters gets you:

  • ALL of our content (thousands of articles, scripts, and forum postings)
  • A daily newsletter (example)
  • A weekly news round up (example)
  • The opportunity to ask and answer questions in our forums
  • A daily Question of the Day to test and help you increase your knowledge of SQL Server.

We ask that you give the newsletter a try for a week. Over 200,000 SQL Server Professionals a day find it entertaining and useful. If not, you are welcome to unsubscribe at anytime.

Steve Jones
Editor, SQLServerCentral.com