Archive

Archive for the ‘Last Execution Date for Stored Procedure’ Category

How to find Last Execution Date of Stored Procedure

October 25, 2010 2 comments

I have seens this common question on few SQL Server Forum that how can i get the last execution date for Stored Procedur or when was the stored procedure exedcuted last.

Now How to achive this?

Every SQL Stament sent to SQL Server is PARSED,COMPILEd and EXECTED.SQL Server maintains QUERY PLAN for each and every statement and keeps it in the system tables.

Which we can query using DMV’s.Query Plans are flushed out if SQL Server Service gets started manulally or automatically(In cluster mode)/runs update stats command / reindexing / usinf DBCC CACHE Clean Commands.

To get last execution date of the stored procedure if SQL Server has the Query Plan for it.

SELECT qs.sql_handle,qs.statement_start_offset,qs.statement_end_offset,

qs.creation_time,qs.last_execution_time,qp.dbid,qp.objectid,st.text
FROMsys.dm_exec_query_statsAS qs
CROSSAPPLYsys.dm_exec_sql_text(qs.sql_handle)AS st
CROSSAPPLYsys.dm_exec_text_query_plan(qs.plan_handle,DEFAULT,DEFAULT)AS qp
WHERE st.textlike‘%USP_CDS_GetUserDetails%’

 

Follow

Get every new post delivered to your Inbox.