Last Run Date on a Stored Procedure in SQL Server

后端 未结 7 1429
北荒
北荒 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 17:01

    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.

提交回复
热议问题