Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 last execution time for a Store Procedure

Author  Topic 

shernee.low
Starting Member

3 Posts

Posted - 2011-04-04 : 11:51:02
Hi..

how do i know the last execution time for a store procedure.
i need to remove the store procedure that not in use.

Tq

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-04-04 : 12:36:09
You can run a trace or just add some audit code to it.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

slimt_slimt
Aged Yak Warrior

746 Posts

Posted - 2011-04-04 : 12:58:15
try this if you are running on sql 2008 or higher. this is something close to what you need:


SELECT

COALESCE(DB_NAME(t.[dbid]),'Unknown') AS [DB Name],
ecp.objtype AS [Object Type],
t.[text] AS [Adhoc Batch or Object Call],
SUBSTRING(t.[text], (qs.[statement_start_offset]/2) + 1,
((CASE qs.[statement_end_offset]
WHEN -1 THEN DATALENGTH(t.[text]) ELSE qs.[statement_end_offset] END
- qs.[statement_start_offset])/2) + 1) AS [Executed Statement]
,qs.[last_execution_time] AS [Last Exec Time]
,qs.[creation_time] AS [Creation Time]

FROM sys.dm_exec_query_stats AS qs
JOIN sys.dm_exec_cached_plans ecp
ON qs.plan_handle = ecp.plan_handle
CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) AS t
where
ecp.objtype = 'Proc'

order by [Last Exec Time] desc
Go to Top of Page

shernee.low
Starting Member

3 Posts

Posted - 2011-04-06 : 12:15:44
Hi Slimt

i am using SQL 2005...
i try to execute the script given, the last exec time and creation time return the same date but with time different.

any other way i can check..

tq
Go to Top of Page
   

- Advertisement -