Call now: (800) 766-1884  



 Home


 SQL Server Tips
 SQL Server Training

 SQL Server Consulting
 SQL Server Support
 SQL Server Remote DBA



 Articles
 Services
 SQL Server Scripts
 Scripts Menu



 

 

 

 
 

SQL Server dm_exec_query_stats scripts


SQL Server Tips by Burleson Consulting
 



DMV queries:

-- Get Top 20 executed stored procedures ordered by total worker time (CPU pressure)

select
   top 20 qt.text                                                              as 'procedure name',
   qs.total_worker_time                                                        as 'tot worker time',
   qs.total_worker_time/qs.execution_count                                     as 'avg worker time',
   qs.execution_count                                                          as 'executions',
   isnull(qs.execution_count/datediff(second, qs.creation_time, getdate()), 0) as 'calls/second',
   isnull(qs.total_elapsed_time/qs.execution_count, 0)                         as 'avg elapsed time',
   qs.max_logical_reads,
   qs.max_logical_writes,
   datediff(minute, qs.creation_time, getdate())                               as 'age in cache'
from
   sys.dm_exec_query_stats                         as qs
   cross apply
   sys.dm_exec_sql_text(qs.sql_handle)             as qt
where
   qt.dbid = db_id()
order by
   qs.total_worker_time desc

 


-- Top 100 executed stored procedures by executions
select
   top 100 qt.text                                                  as 'procedure name',
   qs.execution_count                                               as 'execution count',
   qs.execution_count/datediff(second, qs.creation_time, getdate()) as 'calls/second',
   qs.total_worker_time/qs.execution_count                          as 'avg worker time',
   qs.total_worker_time                                             as 'tot worker time',
   qs.total_elapsed_time/qs.execution_count                         as 'avg elapsed time',
   qs.max_logical_reads,
   qs.max_logical_writes,
   qs.total_physical_reads,
   datediff(minute, qs.creation_time, getdate())                    as 'age in cache'
from
      sys.dm_exec_query_stats                                       as qs
   cross apply
      sys.dm_exec_sql_text(qs.sql_handle)                           as qt
where
   qt.dbid = db_id()
order by
   qs.execution_count desc




 

 

 

Burleson Consulting Remote DB Administration


 

 


 

 

 

 

 
Burleson is the America's Team

Note: The pages on this site were created as a support and training reference for use by our staff of DBA consultants.  If you find it confusing, please exit this page.

Errata?  SQL Server technology is changing and we strive to update our SQL Server support information.  If you find an error or have a suggestion for improving our content, we would appreciate your feedback.  Just  e-mail:and include the URL for the page.
 


Burleson Consulting
SQL Server database support

 

Copyright 1996 -  2013 by Vaaltech Web Services. All rights reserved.

Hit Counter