Created
January 13, 2012 01:50
-
-
Save jaredmdobson/1604207 to your computer and use it in GitHub Desktop.
SQL Server 2008 Shows Execution Plan for a given spid.
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
--===================================================== | |
-- Author: Jared Dobson | |
-- Date: 12/22/2010 | |
-- Description: Shows Execution Plan for a given spid. | |
--===================================================== | |
CREATE PROCEDURE sp_queryplan ( @SessionID INT ) | |
AS | |
BEGIN | |
SELECT | |
[DEQP].[query_plan], | |
[DER].[plan_handle] | |
FROM | |
[sys].[dm_exec_requests] AS [DER] | |
CROSS APPLY [sys].[dm_exec_query_plan]([DER].[plan_handle]) AS [DEQP] | |
WHERE | |
[DER].[session_ID] = @SessionID | |
END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you, this is very useful. I hope you don't mind I will share this public. I've discovered your SP purely by accident.