Solved

a stored procedure last executed and  who executed it

Posted on 2016-09-02
6
31 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
Comment Utility
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 3

Assisted Solution

by:Daniel Jones
Daniel Jones earned 166 total points
Comment Utility
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
Comment Utility
can i find out who executed it or who ran the SP ? thanks
0
 
LVL 17

Accepted Solution

by:
dbaSQL earned 334 total points
Comment Utility
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:ScottPletcher
Comment Utility
SQL does not save which user executed a stored procedure.  It would be way too much overhead.
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
MS SQL 2016 from Database to Datawarehouse 6 34
Folder size tool 6 58
Microsoft Lync 2013 4 41
Mssql SQL query 14 20
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
OfficeMate Freezes on login or does not load after login credentials are input.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now