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.

202 Views

Yavuz Selim Kart

I try to explain what I know in software and database. I am still improving myself by doing research on many programming languages. Apart from these, I am also interested in Graphic Design and Wordpress. I also have knowledge about SEO and Social media management. In short, I am a determined person who likes to work hard.

You may also like...

Don`t copy text!