Solved

a stored procedure last executed and  who executed it

Posted on 2016-09-02
6
40 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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Replication question 9 43
Show Results for Latest DateTime in a View 27 25
Deal with apostrophe in stored procedures 8 42
Rename a column in the output 3 14
Sometimes drives fill up and we don't know why.  If you don't understand the best way to use the tools available, you may end up being stumped as to why your drive says it's not full when you have no space left!  Here's how you can find out...
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
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.

777 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