Skip to content

Instantly share code, notes, and snippets.

@juanonsoftware
Last active January 26, 2022 17:33
Show Gist options
  • Save juanonsoftware/76567835d82a70e21934fa816c1f0816 to your computer and use it in GitHub Desktop.
Save juanonsoftware/76567835d82a70e21934fa816c1f0816 to your computer and use it in GitHub Desktop.
A script to list all current locks in SQL server
-- 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