How to identify locked tables and how to release the locks?

Posted on 2014-02-04
Medium Priority
Last Modified: 2014-02-05
One of the SPs in my database takes long time to execute. The same SP executes faster in another DB. My colleague suggests that the tables could be locked in my DB and I've to release the locks (in which the SP refers) from the tables. How to identify the issue is due to locks and how to release them?

Please do suggest. Thanks.
Question by:Easwaran Paramasivam
LVL 45

Accepted Solution

AndyAinscow earned 500 total points
ID: 39831888
Are the tables (in the two different databases) the SP operate upon identical in structure ?  (An index in one table that isn't in the other can make a vast difference to the time an SP takes to complete).
LVL 23

Assisted Solution

by:Patrick Bogers
Patrick Bogers earned 500 total points
ID: 39831891

Look under management (right click) and select View locks by object.
LVL 16

Assisted Solution

by:Surendra Nath
Surendra Nath earned 500 total points
ID: 39831956
you can use the sp_lock2 stored procedure to find out if there are any locks on the tables involved
if that stored procedure is not already there in your database then you can get it from here


I suggest you also try to update the statistics once and see if it resolves the performance issue


the above statement will update the stats of all the tables involved...
LVL 40

Assisted Solution

by:Jacques Bourgeois (James Burger)
Jacques Bourgeois (James Burger) earned 500 total points
ID: 39832963
Andy has the most common and easiest to fix problem with slow stored procedures: tables that are not indexed properly.

The difference of speed between 2 databases might be that the amount or the values of the joining and ordering fields are different from one database to another. The amount of traffic can also play a role.

If you find out that locks are the problem, be careful. Locks are usually there for a good reason: to prevent multiple writes to the same data from 2 different sources at the same time. Removing them to speed up things would create more important problems.

Is your application the only one that uses that database? If so review your code for the most common cause of locks: transactions. You might be starting transactions that you do not commit or rollback as soon as the operations are finished, so they are holding locks uselessly. You might also be using transactions in places where they are not needed.

If other applications use that database, try to see if the same thing could not happen in these too.
LVL 16

Author Closing Comment

by:Easwaran Paramasivam
ID: 39835974

Featured Post

A proven path to a career in data science

At Springboard, we know how to get you a job in data science. With Springboard’s Data Science Career Track, you’ll master data science  with a curriculum built by industry experts. You’ll work on real projects, and get 1-on-1 mentorship from a data scientist.

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.

Join & Write a Comment

In this article, we will see two different methods to recover deleted data. The first option will be using the transaction log to identify the operation and restore it in a specified section of the transaction log. The second option is simpler and c…
This article describes and provides a custom-made tool I wrote to give businesses a means of identifying commercial music content, without having to expend too much effort. Business recordings are easily identified from possibly illegal music files …
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how the fundamental information of how to create a table.

623 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