SQL Server 2008中查看锁信息

Posted 知识无限

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SQL Server 2008中查看锁信息相关的知识,希望对你有一定的参考价值。

;with tran_locks as(
select resource_type,db_name(resource_database_id) as db_name,resource_description
   ,object_name(resource_associated_entity_id,resource_database_id) as object_name,request_mode,request_type,request_status,request_session_id
   from sys.dm_tran_locks
   where resource_type=‘OBJECT‘
union
select resource_type,db_name(resource_database_id) as db_name,resource_description
   ,object_name(p.object_id,l.resource_database_id) as object_name,request_mode,request_type,request_status,request_session_id
   from sys.dm_tran_locks as l
   join sys.partitions as p on l.resource_associated_entity_id=p.hobt_id
   where resource_type in (‘PAGE‘,‘KEY‘)
union
select resource_type,db_name(resource_database_id) as db_name,resource_description
   ,null as object_name,request_mode,request_type,request_status,request_session_id
   from sys.dm_tran_locks as l
   where resource_type not in (‘OBJECT‘,‘PAGE‘,‘KEY‘)
)select l.*,s.login_name,text from tran_locks as l
    join sys.dm_exec_sessions as s on s.session_id=l.request_session_id
    left join sys.dm_exec_requests as r on r.session_id=s.session_id
    cross apply sys.dm_exec_sql_text(sql_handle)
    where not (resource_type=‘DATABASE‘ and request_mode=‘S‘ and request_type=‘LOCK‘ and request_status=‘GRANT‘)
    --and db_name=‘‘
    --and object_name=‘‘
    order by db_name,object_name,request_type

以上是关于SQL Server 2008中查看锁信息的主要内容,如果未能解决你的问题,请参考以下文章

如何查看sql server 2008的SQL语句执行错误日志

sql server 2008怎么查看日志文件

sql server 2008不用查询语句怎样查看新建的表的信息?像2000中的企业管理器中有个返回所有列一样

《SQL Server 2008从入门到精通》--20180716

sql server 查看锁表SQL

Sql server2008! SQL server服务无法启动,并显示错误17113, 修复Sql server2008失败!