July 23, 2007 at 7:19 am
Hello,
I have a trigger defined for a permanent table..
This trigger Updates more than 3000 records.
Every time i do a update to the table I get a time out error because of the Trigger.
Every help is welcome and would be thankfull
-Sharan
July 23, 2007 at 8:13 am
Could you post the trigger so we can have a look at it?
Pretty hard to guess what's wrong with it, other than it's probably 'bad' in one way or another...
/Kenneth
July 23, 2007 at 9:55 am
My guess is you're doing too much work in the trigger. Trigger code should be tight and do minimal work.
July 23, 2007 at 12:53 pm
My guess... Trigger is causing excessive locking!
Details on the implementation are needed so that we can help you
* Noel
July 23, 2007 at 10:07 pm
Thanks..
The Trigger Updates Table2 based on the modification done to the 8 columns in Table1 for which the Trigger is defined.
If Update(Table1.Column1)
Update Table2
Set Table2.Column1 = @data
Where (Based on certain Criteria)
Similar Kind of statements has been defined for Other 7 columns.
How to determine the Excessive Lockings caused by the Triggers?
-Sharan
July 23, 2007 at 10:07 pm
Thanks..
The Trigger Updates Table2 based on the modification done to the 8 columns in Table1 for which the Trigger is defined.
If Update(Table1.Column1)
Update Table2
Set Table2.Column1 = @data
Where (Based on certain Criteria)
Similar Kind of statements has been defined for Other 7 columns.
How to determine the Excessive Lockings caused by the Triggers?
-Sharan
July 23, 2007 at 11:10 pm
This is what I call "RBAR" (pronounced "ree-bar" and is a "Modenism" for "Row by Agonizing Row") because you have variables on the right side of an update. The only way we're going to be able to give you a good recommendation on this is if you post the code for the whole trigger so we can help you turn it into some high speed set based code. 3000 rows of update should take well less than a second
--Jeff Moden
Change is inevitable... Change for the better is not.
July 24, 2007 at 12:35 am
A quick Question, wat are the different ways to increase the Connection and Command Timeout Properties of the sql connection string?
-Sharan
July 24, 2007 at 4:53 am
The default is like 30 seconds. It's already 30 times bigger than it needs to be. So I'd suggest you improve the performance of the code instead of the length of the time out.
July 24, 2007 at 5:48 am
You can extend the command timeout via a simple property if you're using either ADO or ADO.Net, but as noted it's not a good idea - unless! - its more of a back office type job that just needs to run and you have bigger fish to fry. Hopefully you can make it faster with better indexing, query, etc, but at some point you might wind up in the same place again if the number of records gets larger. The only permanent fix is to just queue something to be done in the trigger, then act on it async via a job or other process. That might be just dumping the entire deleted (or inserted) table into a holding table, or just grabbing the id's of the modified rows.
July 24, 2007 at 5:57 am
Andy, Can you explain it in detail on what you wanted to say.
Thanks
-Sharan
July 24, 2007 at 6:05 am
Create WorkQueueTable (permanent table)
(
id int
)
then in the trigger, you simply insert the ids in that table
Then you assign a job to run each X minutes or whatever delay you feel is right, and then in that job you run the long queries. But to be perfectly honest I never needed to do that, ever. I always found a better way to improve my statements' performance beyond that point of no return. That's why I'd recommend AGAIN that you do that FIRST.
July 24, 2007 at 6:06 am
Your trigger must look like this:
UPDATE T2
SET Column1 = i.ColumnA
FROM inserted i -- system table containing rows from Table1 affected by update/insert
INNER JOIN Table2 T2 ON {join criteria between tables Table1(represented by inserted here) and Table2}
Where (Based on certain Criteria)
That's it.
One statement. No loops, no cursors.
And if you need to check if any of 8 columns updated read about COLUMNS_UPDATED ( ) in CREATE TRIGGER topic in BOL.
_____________
Code for TallyGenerator
July 24, 2007 at 7:46 am
I'd recommend that changing the timeout is a patch, not a fix. All you'd end up doing is allowing code that desparatly needs to be fixed to take its sweet time running. I'll say it again... Post the code and let us see what we can do.
--Jeff Moden
Change is inevitable... Change for the better is not.
July 24, 2007 at 8:28 am
-Sharan
Viewing 15 posts - 1 through 15 (of 21 total)
You must be logged in to reply to this topic. Login to reply