Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

store procedure -  last execution

Posted on 2016-08-06
2
Medium Priority
?
73 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 1000 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 1000 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
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…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how the fundamental information of how to create a table.

877 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