Bloggin in the UK RSS 2.0
 Friday, April 01, 2005

We use a set of three triggers to Audit all Insert, Update and Delete activity on every table in our database. We have a piece of SQL that auto generates trigger create scripts for each table automatically. This means that every time we make a structural alteration to a table we must re-run the script for that table and update the triggers as part of the release.

In the tables with lots of columns we noticed poor performance during updates, looking in Query Analyser at the Execution Plan revealed that for each update there were multiple scans of the Inserted and the Deleted pseudo tables.

This was happening because the Update Audit trigger had an Insert statement in it for each column in the table. The Insert statement caused the scan of the Inserted and Deleted pseudo tables. I remembered reading in the books online that you can use IF UPDATE (column) to test if a column has been updated, by placing this statement around each Insert statement we were able to greatly increase the speed with which the trigger operates, because the Inserted/Deleted scans were only happening for the columns that had been updated.

I dedicate this blog post to Kimberly Tripp's interview on .Net Rocks, it was a great show full of invaluable SQL Server performance tuning advice.

 

 

Friday, April 01, 2005 3:43:23 PM (GMT Standard Time, UTC+00:00)  #    Comments [2] -

Archive
<July 2010>
SunMonTueWedThuFriSat
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2010
Charlie Barker
Sign In
Statistics
Total Posts: 169
This Year: 11
This Month: 2
This Week: 0
Comments: 77
Themes
Pick a theme:
All Content © 2010, Charlie Barker
DasBlog theme 'Business' created by Christoph De Baene (delarou)