Solved

store procedure -  last execution

Posted on 2016-08-06
2
62 Views
Last Modified: 2016-08-10
Hi experts

it is possible to know when he was executed (date and time) for the last time a stored procedure
0
Comment
Question by:enrique_aeo
2 Comments
 
LVL 41

Accepted Solution

by:
Sharath earned 250 total points
ID: 41745990
check this.

http://sqlfool.com/2009/08/find-recently-executed-stored-procedures/

Select DB_Name(dest.[dbid]) As 'databaseName'
    , Object_Name(dest.objectid, dest.[dbid]) As 'procName'
    , Max(deqs.last_execution_time) As 'last_execution'
From sys.dm_exec_query_stats As deqs
Cross Apply sys.dm_exec_sql_text(deqs.sql_handle) As dest
Where dest.[text] Like '%yourTableName%' -- replace
    And dest.[dbid] Is Not Null  -- exclude ad-hocs
Group By db_name(dest.[dbid])
    , Object_Name(dest.objectid, dest.[dbid])
Order By databaseName
    , procName
Option (MaxDop 1);

Open in new window

0
 
LVL 13

Assisted Solution

by:geek_vj
geek_vj earned 250 total points
ID: 41746099
Please note that you can retrieve this information only from the available info from cache and there is no way to retrieve if the specified proc was flushed out of cache either by system or manually.

Here is the query:

declare @proc_nm sysname

-- select the procedure name here
set @proc_nm = 'SP name here'

select s.last_execution_time
from sys.dm_exec_query_stats s
cross apply sys.dm_exec_query_plan (s.plan_handle) p
where object_name(p.objectid, db_id('AdventureWorks')) = @proc_nm

-- Ref: http://stackoverflow.com/questions/130753/last-time-a-stored-procedure-was-executed

Please understand that this might give partial results as it will pull information only from the current cache.
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SQL 2012 AOG and SQL2014 AOG 76 60
T-SQL Query - Group By Year 3 28
Need SSIS project 2 24
SQL 2012 Instance Problem 3 48
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question