查询阻塞的sql

时间:2021-04-12 09:21:56

WITH ProcessCTE(blocked) AS
(
SELECT blocked FROM sys.sysprocesses WHERE blocked>0

union

SELECT spid FROM sys.sysprocesses WHERE blocked>0
)
SELECT a.*
FROM (
SELECT TEXT,AA.* FROM sys.sysprocesses AA
CROSS APPLY sys.dm_exec_sql_text(AA.sql_handle)
) a
JOIN ProcessCTE bucte WITH(NOLOCK)
ON bucte.blocked=a.spid
ORDER BY a.blocked