Last active
January 26, 2022 17:33
-
-
Save juanonsoftware/76567835d82a70e21934fa816c1f0816 to your computer and use it in GitHub Desktop.
A script to list all current locks in SQL server
This file contains 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
-- With SQL | |
select handle.text as sql, * from | |
( | |
select DB_NAME(dbid) as dbname, * | |
from master.dbo.sysprocesses | |
where blocked <> 0 | |
union | |
select DB_NAME(dbid) as dbname, * | |
from master.dbo.sysprocesses | |
where spid in ( | |
select blocked | |
from master.dbo.sysprocesses | |
where blocked <> 0 | |
) | |
) p | |
CROSS APPLY sys.dm_exec_sql_text(p.sql_handle) AS handle | |
order by p.waittime desc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment