32

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

4

2 回答 2

87

您可以使用sp_lock(and sp_lock2),但在 SQL Server 2005 及以后的版本中,不推荐使用此方法,而支持查询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
于 2009-03-01T09:21:54.077 回答
8

sp_lock

When reading sp_lock information, use the OBJECT_NAME( ) function to get the name of a table from its ID number, for example:

SELECT object_name(16003073)

EDIT :

There is another proc provided by microsoft which reports objects without the ID translation : http://support.microsoft.com/kb/q255596/

于 2009-03-01T08:56:55.387 回答