Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
gmetaj
Starting Member
33 Posts |
Posted - 2004-08-09 : 17:23:22
|
| I am using FOR UPDATE triggers to audit a table that has 67 fields. My problem is that this slows down the system significantly. I have narrowed down the problem to the size (Lines of code) that need to be compiled after the trigger has been fired. There is about 67 IF Update(fieldName) inside the trigger and a not very complex select statement inside the if followed by an insert to the audit table. When I leave only a few IF-s in the trigger and comment the rest of the code performance increased dramatically. It seems like it is checking every single UPdate() statement. Assuming that this was slowing down due to doing a select for every update i tried to do to seperate selects in the beginning from Deleted and Inserted and assigning columns name to specific variables and instead of doing if Update(fieldName) i did if @DelFieldName <> @InsFieldName beginINSERT INTO AUDITSELECT WHAT I NEEDENDThis did not improve performance. If you have any ideas on how to get around this issue please let me know. Below is an example of what my triggers look like. ------------------------------------Trigger 1 -- this was my original designCREATE trigger1 on TableFOR UPDATEAS if update(field1)begininsert into AuditSELECT What I needENDif update(field2)begininsert into AuditSELECT What I needEND... Repeated about 65 more times if update(field67)insert into AuditSELECT What I needEND---------------------------------------------------------------------------Trigger 2 -- this is what i tried but did not improve performanceCREATE trigger2 on TableFOR UPDATEAS Declare @DelField1 varcharDeclare @DelField2 varchar..Declare @DelField67 varcharSelect @DelField1 = DelField1, @DelField2 = DelField2, ... @DelField3 = DelField3From DeletedDeclare @InsField1 varcharDeclare @InsField2 varchar..Declare @InsField67 varcharSelect @insField1 = InsField1, @insField2 = InsField2, ... @InsField3 = InsField3From Inserted-- I do not do if Update() but instead compare variablesif @DelField1 <> InsField1beginInsert into AUDITSELECT what I needendif @DelField2 <> InsField2beginInsert into AUDITSELECT what I needend.........if @DelField67 <> InsField67beginInsert into AUDITSELECT what I needend----------------------------------------------IF you have any idea how to optimize this please let me know. Any input is greatly appreciated. Thanks,Gent |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
|
|
|