Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find Locked Table in SQL Server

How can we find which table is locked in the database? Please, suggest.

like image 777
user47957 Avatar asked Mar 01 '09 07:03

user47957


People also ask

How do I find locked objects in SQL Server?

You can use the DB_NAME() function to identify the database. The identification number of the object on which the lock is held. You can use the OBJECT_NAME() function in the related database to identify the object.

How do I find my lock table?

In MySQL, locked tables are identified using the SHOW OPEN TABLES command. In its simplest form is displays all locked tables. All open tables in the table cache are listed, but the IN_USE column indicates of the table is locked.

How do you unlock a locked table in SQL Server?

Use the UNLOCK TABLE statement in a database that does not support transaction logging to unlock a table that you previously locked with the LOCK TABLE statement. The UNLOCK TABLE statement is an extension to the ANSI/ISO standard for SQL.


1 Answers

You can use sp_lock (and sp_lock2), but in SQL Server 2005 onwards this is being deprecated in favour of querying sys.dm_tran_locks:

select       object_name(p.object_id) as TableName,      resource_type, resource_description from     sys.dm_tran_locks l     join sys.partitions p on l.resource_associated_entity_id = p.hobt_id 
like image 117
Mitch Wheat Avatar answered Oct 10 '22 07:10

Mitch Wheat