How to check date of last change in stored procedure or function in SQL server

后端 未结 8 1899
悲&欢浪女
悲&欢浪女 2020-12-12 09:36

I need to check when function was changed last time. I know how to check creation date (it is in function properties window in SQL Server Management Studio).
I found tha

8条回答
  •  没有蜡笔的小新
    2020-12-12 09:44

    You can use this for check modify date of functions and stored procedures together ordered by date :

    SELECT 'Stored procedure' as [Type] ,name, create_date, modify_date 
    FROM sys.objects
    WHERE type = 'P' 
    
    UNION all
    
    Select 'Function' as [Type],name, create_date, modify_date
    FROM sys.objects
    WHERE type = 'FN'
    ORDER BY modify_date DESC
    

    or :

    SELECT type ,name, create_date, modify_date 
    FROM sys.objects
    WHERE type in('P','FN') 
    ORDER BY modify_date DESC
    -- this one shows type like : FN for function and P for stored procedure
    

    Result will be like this :

    Type                 |  name      | create_date              |  modify_date
    'Stored procedure'   | 'firstSp'  | 2018-08-04 07:36:40.890  |  2019-09-05 05:18:53.157
    'Stored procedure'   | 'secondSp' | 2017-10-15 19:39:27.950  |  2019-09-05 05:15:14.963
    'Function'           | 'firstFn'  | 2019-09-05 05:08:53.707  |  2019-09-05 05:08:53.707
    

提交回复
热议问题