在 SQL Server 中查找锁定的表

我们如何找到数据库中被锁定的表?请,建议.

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

推荐答案

你可以使用 sp_lock(和 sp_lock2),但在 SQL Server 2005 及以后的版本中,不推荐使用此功能,而支持查询 sys.dm_tran_locks:

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

相关文章