Solved

Disabling trigger inadvertently locks table on SQL Server

Posted on 2011-09-05
4
254 Views
Last Modified: 2012-06-21
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
Comment
Question by:advfinance
  • 2
  • 2
4 Comments
 
LVL 15

Accepted Solution

by:
Anuj earned 500 total points
ID: 36483470
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
 
LVL 5

Author Comment

by:advfinance
ID: 36483551
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
 
LVL 15

Expert Comment

by:Anuj
ID: 36483593
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
 
LVL 5

Author Closing Comment

by:advfinance
ID: 36921795
No reason
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
I have a large data set and a SSIS package. How can I load this file in multi threading?
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now