View lock information in SQL Server 2008

Source: Internet
Author: User

; 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

View lock information in SQL Server 2008

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.