Disabling trigger inadvertently locks table on SQL Server

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!!!

LVL 5
advfinanceAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
AnujConnect With a Mentor SQL Server DBACommented:
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.
0
 
advfinanceAuthor 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.
0
 
AnujSQL Server DBACommented:
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..
0
 
advfinanceAuthor Commented:
No reason
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.