Skip to content

Instantly share code, notes, and snippets.

@bartread
Created January 4, 2017 07:43
Show Gist options
  • Save bartread/ef6e7d884be68693cf7a2469ed2d6732 to your computer and use it in GitHub Desktop.
Save bartread/ef6e7d884be68693cf7a2469ed2d6732 to your computer and use it in GitHub Desktop.
Get execution plans for top SQL queries by CPU time
SELECT TOP 5 total_worker_time/execution_count AS [Avg CPU Time],
Plan_handle, query_plan
FROM sys.dm_exec_query_stats AS qs
CROSS APPLY sys.dm_exec_query_plan(qs.plan_handle)
ORDER BY total_worker_time/execution_count DESC;
GO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment