How to get list of the most expensive queries in SQL Server

microsoft_sql_server_icon (1)

SELECT TOP 20
    (total_logical_reads + total_logical_writes) / execution_count AS AverageIO
    ,(total_logical_reads + total_logical_writes) AS TotalIO
    ,qt.text Query
    ,o.name ObjectName
    ,DB_NAME(qt.dbid) AS DATABASEName
FROM 
    sys.dm_exec_query_stats qs
        CROSS APPLY
    sys.dm_exec_sql_text(qs.sql_handle) AS qt
        LEFT OUTER JOIN
    sys.objects o ON o.object_id = qt.objectid          
ORDER BY AverageIO DESC
Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s