Find Locked Table in SQL Server

user47957 picture user47957 · Mar 1, 2009 · Viewed 140.9k times · Source

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

Answer

Mitch Wheat picture Mitch Wheat · Mar 1, 2009

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