How can we find which table is locked in the database? Please, suggest.
我们如何找到哪个表被锁定在数据库中?请建议。
2 个解决方案
#1
82
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
:
您可以使用sp_lock(和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
#2
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:
在读取sp_lock信息时,使用OBJECT_NAME()函数从表的ID号获取表的名称,例如:
SELECT object_name(16003073)
选择object_name(16003073)
EDIT :
编辑:
There is another proc provided by microsoft which reports objects without the ID translation : http://support.microsoft.com/kb/q255596/
微软提供的另一个proc报告对象没有ID翻译:http://support.microsoft.com/kb/q255596/。
#1
82
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
:
您可以使用sp_lock(和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
#2
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:
在读取sp_lock信息时,使用OBJECT_NAME()函数从表的ID号获取表的名称,例如:
SELECT object_name(16003073)
选择object_name(16003073)
EDIT :
编辑:
There is another proc provided by microsoft which reports objects without the ID translation : http://support.microsoft.com/kb/q255596/
微软提供的另一个proc报告对象没有ID翻译:http://support.microsoft.com/kb/q255596/。