SQL SERVER – Find Most Expensive Queries Using DMV

SELECT TOP 10 SUBSTRING(qt.TEXT, (qs.statement_start_offset/2)+1,
((
CASE qs.statement_end_offset
WHEN -THEN DATALENGTH(qt.TEXT)
ELSE qs.statement_end_offset
END qs.statement_start_offset)/2)+1),
qs.execution_count,
qs.total_logical_readsqs.last_logical_reads,
qs.total_logical_writesqs.last_logical_writes,
qs.total_worker_time,
qs.last_worker_time,
qs.total_elapsed_time/1000000 total_elapsed_time_in_S,
qs.last_elapsed_time/1000000 last_elapsed_time_in_S,
qs.last_execution_time,
qp.query_plan
FROM sys.dm_exec_query_stats qs
CROSS APPLY sys.dm_exec_sql_text(qs.sql_handleqt
CROSS APPLY sys.dm_exec_query_plan(qs.plan_handleqp
ORDER BY qs.total_logical_reads DESC -- logical reads
-- ORDER BY qs.total_logical_writes DESC -- logical writes
-- ORDER BY qs.total_worker_time DESC -- CPU time

 

The query for this is very simple. It uses two DMVs and created following quick script for the same.

SELECT session_idTEXT
FROM 
sys.dm_exec_connections
CROSS APPLY sys.dm_exec_sql_text(most_recent_sql_handleAS ST


Crie um site com

  • Totalmente GRÁTIS
  • Centenas de templates
  • Todo em português

Este site foi criado com Webnode. Crie um grátis para você também!