• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 266
  • Last Modified:

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

0
advfinance
Asked:
advfinance
  • 2
  • 2
1 Solution
 
AnujSQL 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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now