Solved

a stored procedure last executed and  who executed it

Posted on 2016-09-02
6
45 Views
Last Modified: 2016-10-22
Hi
 how can find out a stored procedure last executed and who executed it from sql sever 2012, thanks
0
Comment
Question by:tristonyip
6 Comments
 
LVL 17

Assisted Solution

by:dbaSQL
dbaSQL earned 334 total points
ID: 41782439
Use the sys.dm_exec_query DMV for details on when it was last executed.


The sys.dm_exec_query DMV returns aggregate performance statistics for cached query plans.  Important note:  It is only cached query plans.  When a plan is removed from the cache (or you restart the SQL Server service), the corresponding rows are eliminated from this reference.

     SELECT
           qt.[text] [ProcedureName],
           qs.last_execution_time [LastRan],
           qs.execution_count [ExecutionCount]  
     FROM
           sys.dm_exec_query_stats qs CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) qt
     WHERE
           qt.text LIKE '%your procedure name%'
0
 
LVL 4

Assisted Solution

by:Daniel Jones
Daniel Jones earned 166 total points
ID: 41782535
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('DBNAME')) = @proc_nm 

Open in new window

It will tell you the last time a stored proc was executed.

As far as I know who ran it is not recorded. You could use profiler to recored this.
0
 

Author Comment

by:tristonyip
ID: 41786121
can i find out who executed it or who ran the SP ? thanks
0
 
LVL 17

Accepted Solution

by:
dbaSQL earned 334 total points
ID: 41786246
Retroactively, I am not too sure if you can identify who executed a procedure. Proactively, however, I believe you can use a trace or even an audit.
0
 
LVL 69

Expert Comment

by:Scott Pletcher
ID: 41786372
SQL does not save which user executed a stored procedure.  It would be way too much overhead.
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

I have a large data set and a SSIS package. How can I load this file in multi threading?
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
This tutorial will walk an individual through the process of configuring basic necessities in order to use the 2010 version of Data Protection Manager. These include storage, agents, and protection jobs. Launch Data Protection Manager from the deskt…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

821 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