How to Find the Slowest Queries in SQL Server in 60 Seconds

👉 How to Find the Slowest Queries in SQL Server in 60 Seconds 🚀

Hi SQL SERVER Guys,

You don’t need expensive tools.

You don’t need hours of investigation.
You just need to know WHERE to look.

👉 Today I’ll show you how to find the slowest queries in less than 60 seconds.


P.S. If you missed my previous post, check it out here:
Why TempDB Is Slowing Down Your Entire Server 🔥



🧠 What Are DMVs?

DMVs (Dynamic Management Views) are SQL Server internal views that expose a lot of internal information of SQL Server:

  • Query performance
  • CPU usage
  • IO stats
  • Execution metrics

👉 Think of them as your real-time X-ray or the Blood Exam of your SQL SERVER 


🔥 Find Slow Queries with DMVs


SELECT TOP 10
    qs.total_worker_time / qs.execution_count AS avg_cpu,
    qs.total_elapsed_time / qs.execution_count AS avg_duration,
    qs.total_logical_reads / qs.execution_count AS avg_reads,
    qs.execution_count,
    SUBSTRING(qt.text, qs.statement_start_offset/2,
    (CASE WHEN qs.statement_end_offset = -1
          THEN LEN(CONVERT(NVARCHAR(MAX), qt.text)) * 2
          ELSE qs.statement_end_offset END - qs.statement_start_offset)/2) AS query_text
FROM sys.dm_exec_query_stats qs
CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) qt
ORDER BY avg_duration DESC;

👉 This shows your worst queries instantly. Copy , Paste and Try ...


📊 Query Store

Introduced in SQL Server 2016, Query Store changed everything.

  • Stores query history
  • Keeps execution plans
  • Tracks performance over time

💣 Unlike DMVs it survives restarts


🔥 Get Info From Query Store Query


SELECT TOP 10
    rs.avg_duration,
    rs.avg_cpu_time,
    rs.avg_logical_io_reads,
    qt.query_sql_text
FROM sys.query_store_runtime_stats rs
JOIN sys.query_store_plan p ON rs.plan_id = p.plan_id
JOIN sys.query_store_query q ON p.query_id = q.query_id
JOIN sys.query_store_query_text qt ON q.query_text_id = qt.query_text_id
ORDER BY rs.avg_duration DESC;

⚡ Top CPU / IO Queries

Top CPU


SELECT TOP 10
    total_worker_time AS CPU,
    execution_count,
    text
FROM sys.dm_exec_query_stats
CROSS APPLY sys.dm_exec_sql_text(sql_handle)
ORDER BY total_worker_time DESC;

Top IO


SELECT TOP 10
    total_logical_reads AS IO,
    execution_count,
    text
FROM sys.dm_exec_query_stats
CROSS APPLY sys.dm_exec_sql_text(sql_handle)
ORDER BY total_logical_reads DESC;

💣 Final Truth

“Your server is not slow… typically your queries are.”


📚 Related Posts

Biondi Luca @2026 - Sharing Knowlegde Gained for Passion. Share my posts if you like and found them useful.

Comments

I Post più popolari

Speaking to Sql Server, sniffing the TDS protocol

SQL Server, find text in a Trigger, Stored Procedures, View and Function. Two ways and what ways is better

SQL Server, Avoid that damn Table Spool!