Skip to content

Instantly share code, notes, and snippets.

@azborgonovo
Created December 7, 2022 16:18
Show Gist options
  • Save azborgonovo/8487ca5a5dfa5e73dae57ea3d566c785 to your computer and use it in GitHub Desktop.
Save azborgonovo/8487ca5a5dfa5e73dae57ea3d566c785 to your computer and use it in GitHub Desktop.
SQL Server handy scripts
-- Check the BlkBy column
EXEC sp_who2
-- Get all requests that have blocking sessions
SELECT *
FROM sys.dm_exec_requests
WHERE DB_NAME(database_id) = 'YourDBName'
AND blocking_session_id <> 0
-- Get the queries themselves
SELECT text,*
FROM sys.dm_exec_requests
CROSS APPLY sys.dm_exec_sql_text(sql_handle)
WHERE DB_NAME(database_id) = 'YourDBName'
AND blocking_session_id <> 0
-- If there are any transaction blocked, check the following table
SELECT *
FROM sys.dm_tran_session_transactions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment