SQL Server查看被锁的表

select str(request_session_id ,4 ,0) as SPID
      ,convert(varchar(20) ,db_name(resource_database_id)) as db_name 
      ,resource_associated_entity_id
      ,O.name
      ,resource_type
      ,request_type
      ,request_mode
      ,request_status      
from   sys.dm_tran_locks as A   with (nolock)
left join sys.objects as O with (nolock) on A.resource_associated_entity_id=O.[object_id]
where  resource_type <> 'DATABASE'
原文地址:https://www.cnblogs.com/wancy86/p/getlocks.html