How can I find the last modified date, modified user of an stored procedure in SQL Server 2008?

前端 未结 8 673
无人共我
无人共我 2021-02-01 23:50

I need to find the user name of the person who modified a particular stored procedure.

How do I find out when a stored procedure was last modified or compiled in Oracle?

8条回答
  •  遥遥无期
    2021-02-02 00:22

    This can be achieve by running any of the following query.

    SELECT 
        [procedure] = QUOTENAME(OBJECT_SCHEMA_NAME([object_id]))
            + '.' + QUOTENAME(OBJECT_NAME([object_id])),
        last_execution_time,
        avg_execution_time = CONVERT(DECIMAL(30,2), total_worker_time * 1.0 / execution_count),
        max_worker_time
    FROM sys.dm_exec_procedure_stats
    WHERE database_id = DB_ID()
    ORDER BY avg_execution_time DESC;
    

    ------------OR--------------------------------------

    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
    

提交回复
热议问题