SP execution count

Shows the execution count of each stored procedure

Last updated:

Warning: Review and test in a non-production environment before running.

Back to results

The following DMV query shows the execution count of each stored procedure, sorted by the most executed procedures first.

SELECT
 DatabaseName = DB_NAME(st.dbid)
 ,SchemaName = OBJECT_SCHEMA_NAME(st.objectid,dbid)
 ,StoredProcedure = OBJECT_NAME(st.objectid,dbid)
 ,ExecutionCount = MAX(cp.usecounts)
 FROM sys.dm_exec_cached_plans cp
 CROSS APPLY sys.dm_exec_sql_text(cp.plan_handle) st
 WHERE DB_NAME(st.dbid) IS NOT NULL
 AND cp.objtype = 'proc'
GROUP BY
 cp.plan_handle
 ,DB_NAME(st.dbid)
 ,OBJECT_SCHEMA_NAME(objectid,st.dbid)
 ,OBJECT_NAME(objectid,st.dbid)
 ORDER BY MAX(cp.usecounts) DESC;