Question

In Oracle, there's a view called V$SQLAREA that lists statistics on shared SQL area and contains one row per SQL string. It provides statistics on SQL statements that are in memory, parsed, and ready for execution.

There is one column -ROWS_PROCESSED that sums the Total number of rows processed on behalf of this SQL statement.

I'm looking for collateral information in SQLSERVER 2005.

I looked in some of the DMV's (like sys.dm_exec_query_stats), but I haven't found anything related.

@@ROWCOUNT won't be useful to me, as I want incremental statistics information that will sum the rows_processed of the top cpu/io/execution consumption queries in the database.

I would appreciate any help in regards the subject.

Thanks in advance,

Roni.


I saw that when I query the following query, I receive the Query Plan in XML.

Inside the XML plan code, there's a "EstimateRows" part with a number that correlates to the number of estimation rows of the query.

I'm thinking of the option to substr the query_plan column to retreive only the above information (unless I would find it in some system views/tables).

Where can I find the Actual number of rows of the query ? Where is it stored ?

SELECT 
       case when sql_handle IS NULL
           then ' '
           else ( substring(st.text,(statement_start_offset+2)/2,       
   (case when qs.statement_end_offset = -1         
   then len(convert(nvarchar(MAX),st.text))*2      
   else statement_end_offset    
   end - statement_start_offset) /2  ) )
        end as query_text , 
    query_plan,
 FROM sys.dm_exec_query_stats qs 
CROSS APPLY sys.dm_exec_query_plan(qs.plan_handle)
cross apply sys.dm_exec_sql_text(sql_handle) st;
Was it helpful?

Solution

There isn't a direct equivalent especially for rowcounts as far as I know. The relevant dmvs track IO cost which is used to show missing indexed, most expensive queries etc

This will give you stats per SQL statement for current sessions. YMMV: I've just put it together based on scripts I have lying around.

SELECT 
    *
FROM 
    sys.dm_exec_query_stats  QS
    CROSS APPLY 
    sys.dm_exec_sql_text(sql_handle) ST

My scripts are based on the links I mentioned here

OTHER TIPS

You can use the system variable @@rowcount to know the number of records affected by last statement.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top