Row count int sys.dm_exec_query_stats


SQL 2012 has added 4 new columns 
total_rows,
last_rows,
min_rows,
max_rows  in sys.dm_exec_query_stats DMV
This will help us to find the queries which are returning large number of results and we can optimized them 

SELECT QS.*,
       Substring(ST.text,
                        ( QS.statement_start_offset /2 ) + 1,
                        (( CASE statement_end_offset
                           WHEN 1 THEN Datalength(st.text)
                                                      ELSE QS.statement_end_offset
                           END QS.statement_start_offset )/ 2 ) + 1) AS statement_text
FROM   sys.dm_exec_query_statsAS QS
       CROSS APPLY sys.Dm_exec_sql_text(QS.sql_handle) AS ST
ORDER  BY max_rows DESC

Leave a comment


Design a site like this with WordPress.com
Get started