Solved

store procedure -  last execution

Posted on 2016-08-06
2
57 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 40

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

809 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