Last Run Date on a Stored Procedure in SQL Server
In a nutshell, no.
However, there are "nice" things you can do.
- Run a profiler trace with, say, the stored proc name
- Add a line each proc (create a tabel of course)
- "
INSERT dbo.SPCall (What, When) VALUES (OBJECT_NAME(@@PROCID), GETDATE()
"
- "
- Extend 2 with duration too
There are "fun" things you can do:
- Remove it, see who calls
- Remove rights, see who calls
- Add
RAISERROR ('Warning: pwn3d: call admin', 16, 1)
, see who calls - Add
WAITFOR DELAY '00:01:00'
, see who calls
You get the idea. The tried-and-tested "see who calls" method of IT support.
If the reports are Reporting Services, then you can mine the RS database for the report runs if you can match code to report DataSet.
You couldn't rely on DMVs anyway because they are reset om SQL Server restart. Query cache/locks are transient and don't persist for any length of time.
The below code should do the trick (>= 2008)
SELECT o.name,
ps.last_execution_time
FROM sys.dm_exec_procedure_stats ps
INNER JOIN
sys.objects o
ON ps.object_id = o.object_id
WHERE DB_NAME(ps.database_id) = ''
ORDER BY
ps.last_execution_time DESC
Edit 1 : Please take note of Jeff Modens advice below. If you find a procedure here, you can be sure that it is accurate. If you do not then you just don't know - you cannot conclude it is not running.