Created
December 23, 2015 15:04
-
-
Save eldargab/4c6d84bc17dbe9cfa341 to your computer and use it in GitHub Desktop.
Figure out MSSQL lock state
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--============================================ | |
--View Locking in Current Database | |
--Author: Timothy Ford | |
--http://thesqlagentman.com | |
--============================================ | |
SELECT DTL.resource_type, | |
CASE | |
WHEN DTL.resource_type IN ('DATABASE', 'FILE', 'METADATA') THEN DTL.resource_type | |
WHEN DTL.resource_type = 'OBJECT' THEN OBJECT_NAME(DTL.resource_associated_entity_id, SP.[dbid]) | |
WHEN DTL.resource_type IN ('KEY', 'PAGE', 'RID') THEN | |
( | |
SELECT OBJECT_NAME([object_id]) | |
FROM sys.partitions | |
WHERE sys.partitions.hobt_id = | |
DTL.resource_associated_entity_id | |
) | |
ELSE 'Unidentified' | |
END AS requested_object_name, DTL.request_mode, DTL.request_status, | |
DEST.TEXT, SP.spid, SP.blocked, SP.status, SP.loginame | |
FROM sys.dm_tran_locks DTL | |
INNER JOIN sys.sysprocesses SP | |
ON DTL.request_session_id = SP.spid | |
--INNER JOIN sys.[dm_exec_requests] AS SDER ON SP.[spid] = [SDER].[session_id] | |
CROSS APPLY sys.dm_exec_sql_text(SP.sql_handle) AS DEST | |
WHERE SP.dbid = DB_ID() | |
AND DTL.[resource_type] <> 'DATABASE' | |
ORDER BY DTL.[request_session_id]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment