sys.dm_exec_cached_plans not showing any data after executing stored proc multiple times.

SSR 20 Reputation points
2024-02-16T16:39:46.52+00:00

Executed different stored proc multiple times and ran below query to check stats. its not showing any data.

SQL Version : Microsoft SQL Server 2012 (SP4) (KB4018073) - 11.0.7001.0 (X64)

Stored Proc : exec [dbo].[uspGetManagerEmployees] @BusinessEntityID = 7

DB : [AdventureWorks2012] Query:

SELECT  DB_NAME(st.dbid) DBNamee
,OBJECT_SCHEMA_NAME(st.objectid,dbid) SchemaName
,OBJECT_NAME(st.objectid,dbid) StoredProcedure
,MAX(cp.usecounts) Execution_count
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'
AND OBJECT_NAME(st.objectid, dbid) LIKE 'uspGetEmployeeManagers'
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
GO
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,807 questions
SQL Server Transact-SQL
SQL Server Transact-SQL
SQL Server: A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.Transact-SQL: A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
97 questions
{count} votes

3 answers

Sort by: Most helpful
  1. LiHongMSFT-4306 27,016 Reputation points
    2024-02-19T05:50:26.5666667+00:00

    Hi @SSR

    Stored Proc : exec [dbo].[uspGetManagerEmployees] @BusinessEntityID = 7

    While in your query: AND OBJECT_NAME(st.objectid, dbid) LIKE 'uspGetEmployeeManagers'

    Is that a typo?

    Best regards,

    Cosmog Hong


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

  2. Erland Sommarskog 111.3K Reputation points MVP
    2024-02-16T22:31:06.5733333+00:00

    What server collation do you have? If you have a case-sensitive collation, change proc to Proc, because that what it says in the DMV. It could also be a issue with memory pressure. Given the database name, I assume that this is on your laptop or similar and not a server. How much RAM do you have? I have seen on several occasions where things fall out of the cache quite quickly, because Windows things there is memory pressure, and therefore asks SQL Server to trim.

    0 comments No comments

  3. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.