Empty Last Execution Time of Stored Procedure – What It Means

sql-server-2008stored-procedures

I recently ran some scripts to get the last execution time of my DB stored procedures, and the code is below:

SELECT d.object_id, d.database_id, OBJECT_NAME(object_id, database_id) 'proc name',   
d.cached_time, d.last_execution_time, d.total_elapsed_time,  
d.total_elapsed_time/d.execution_count AS [avg_elapsed_time],  
d.last_elapsed_time, d.execution_count  
FROM sys.dm_exec_procedure_stats AS d  
where  DB_Name(d.database_id) = 'MyDB' 
ORDER BY [proc name] ; 

But I noticed that some of my stored procedure are not listed. Then I use the code below to check particularly one of them:

select s.last_execution_time
from sys.dm_exec_procedure_stats s
where OBJECT_NAME(object_id, database_id) = 'my_stored_procedure' 

and I get empty result (but nothing shows in the column).

Just want to know if this means the stored procedure has never executed before, or something else?

Thank you

Best Answer

sys.dm_exec_procedure_stats is not a persisted dataset.

It only shows details for queries that currently exist in the Cache. If the SP hasn't been run for some time then the SP will be removed from the cache in favour of more frequently executed queries.

Also the Cache can be emptied by events such as a Server Reboot, and if the SP hasn't been run since the reboot then it won't be there.