Created
December 7, 2022 16:18
-
-
Save azborgonovo/8487ca5a5dfa5e73dae57ea3d566c785 to your computer and use it in GitHub Desktop.
SQL Server handy scripts
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
-- 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