Last Run Date on a Stored Procedure in SQL Server

后端 未结 7 1420
北荒
北荒 2020-12-07 16:28

We starting to get a lot of stored procedures in our application. Many of them are for custom reports many of which are no longer used. Does anyone know of a query we could

7条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-07 16:46

    This works fine on 2005 (if the plan is in the cache)

    USE YourDb;
    
    SELECT qt.[text]          AS [SP Name],
           qs.last_execution_time,
           qs.execution_count AS [Execution Count]
    FROM   sys.dm_exec_query_stats AS qs
           CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) AS qt
    WHERE  qt.dbid = DB_ID()
           AND objectid = OBJECT_ID('YourProc') 
    

提交回复
热议问题