代码之家  ›  专栏  ›  技术社区  ›  Steven Williams

上次执行存储过程的时间

  •  18
  • Steven Williams  · 技术社区  · 16 年前

    在SQL Server 2000上,是否有方法找出上次执行存储过程的日期和时间?

    2 回复  |  直到 16 年前
        1
  •  8
  •   Danimal    16 年前

    恐怕不需要记录或追踪

        2
  •  23
  •   Alex Angas Colin    13 年前

    如果存储过程仍在过程缓存中,则可以通过查询sys.dm_exec_query_stats dmv来查找上次执行该存储过程的时间。在本例中,我还交叉应用于sys.dm_exec_query_plan dmf,以限定对象ID:

    declare @proc_nm sysname
    
    -- select the procedure name here
    set @proc_nm = 'usp_test'
    
    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('AdventureWorks')) = @proc_nm 
    

    [Source]