Disabling trigger inadvertently locks table on SQL Server

advfinance
advfinance used Ask the Experts™
on
I have a stored procedure that runs every night around midnight, and the main part of it disables a trigger, updates some of the data in the same table as the trigger, and re-enables the trigger again.

This has run absolutely fine every night for the past 4 or 5 years. However, for the last two or three nights, the disable trigger line seems to have locked the table up, as well as the task itself, so we've had to kill the task so that the users can carry on. It does not, however,appear to have run the disable trigger line successfully.

There's nothing else I'm aware of that's running at the same time that's blocking it (sp_who2 shows nothing is blocking the scheduled task, but it is blocking everything else using that table), but I've never come across this before either. We've not substantially changed the table in the last few days either, so I'm getting a bit puzzled!!!

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
SQL Server DBA
Top Expert 2011
Commented:
Disabling the trigger usually put a schema lock on the table, so the other transaction depending on your table will wait until the schema lock is released. This is why you are experiencing performance problems.

Author

Commented:
Normally, I'd agree with that as an answer, but in the script with the disable trigger code, it never got to the next line in the script that disabled the trigger in the first place. Also, the lock had been present for hours - Normally, if I disable a trigger, it just does it, and locks for probably less than a second.
AnujSQL Server DBA
Top Expert 2011

Commented:
Some DML Statements may be running in a transaction this holds IX locks or Exclusive locks on the table, and this makes the DDL operations against the table to wait until the DML is completed..

Author

Commented:
No reason

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial