Solved

Disabling trigger inadvertently locks table on SQL Server

Posted on 2011-09-05
4
259 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Database - Move Tables from one Database to Another 4 50
Linked Server - SP with Param to VIew 7 25
SQL Instance service gone? 5 39
SQL Distinct Question 3 15
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

726 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