Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to remove the lock associated with table

Author  Topic 

aoriju
Posting Yak Master

156 Posts

Posted - 2013-08-07 : 03:10:12
Hi all,

I have a query like this
SELECT TOP 1 * FROM ITAM_RAMS_STAGING

not getting value...seems like lock associated with that table

how to remove the lock if exists

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2013-08-07 : 04:01:09
What do you mean with "Not getting value"?
Do you get an error, or the query finishes but doesn't return a row? Or the query waits and waits and waits..?

If you get an error, you have no problem with locks, unless the error indicates a deadlock.
If you don't get a row back, there are no rows in the table.
If you wait and wait for the query to finish, then yes, you have a locking problem for a reason.

You could try
SELECT TOP(1) * FROM dbo.Itam_Rams_Staging WITH (NOLOCK)
but this approach can lead to whole other problems.


Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-08-07 : 06:31:46
quote:
Originally posted by aoriju

Hi all,

I have a query like this
SELECT TOP 1 * FROM ITAM_RAMS_STAGING

not getting value...seems like lock associated with that table

how to remove the lock if exists



try

EXEC sp_who2 'active'

to check if there are any processes blocking your select. Look for BlkBy column value in the row for your process

use sp_lock for getting idea on locks

http://technet.microsoft.com/en-us/library/ms187749.aspx

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -