Listing the 200 Most CPU-Using Queries in SQL Server
Hello to everyone,
In this article, I will try to give information about listing the 200 most CPU-consuming queries in SQL Server.
In SQL Server, in some cases you may want to list the 200 queries that use the most CPU.
You can easily do this using the code below.
SELECT TOP 200
qs.sql_handle,
qs.execution_count,
qs.total_worker_time,
total_CPU_inSeconds = qs.total_worker_time / 1000000, -- microseconds
average_CPU_inSeconds = (qs.total_worker_time / 1000000) / qs.execution_count, --microseconds
qs.total_elapsed_time,
total_elapsed_time_inSeconds = qs.total_elapsed_time / 1000000, -- microseconds
st.text,
qp.query_plan
FROM sys.dm_exec_query_stats AS qs
CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) AS st
CROSS APPLY sys.dm_exec_query_plan(qs.plan_handle) AS qp
ORDER BY qs.total_worker_time DESC;
Good luck to everyone in business and life.