Created
October 9, 2017 18:38
-
-
Save rodolfofadino/4240ffc0df9afbc0d6b3e8f1773aede9 to your computer and use it in GitHub Desktop.
Find Most Executed Stored Procedures
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment