我需要检查上次更改功能的时间。我知道如何检查创建日期(在SQL Server Management Studio的函数属性窗口中)。
我发现在SQL Server 2000中无法检查修改日期(请看这篇文章:是否可以确定何时在SQL Server 2000中最后一次修改存储过程?)
是否可以在SQL Server 2008中进行检查?MS是否在允许检查它的系统表中添加了一些新功能?
我需要检查上次更改功能的时间。我知道如何检查创建日期(在SQL Server Management Studio的函数属性窗口中)。
我发现在SQL Server 2000中无法检查修改日期(请看这篇文章:是否可以确定何时在SQL Server 2000中最后一次修改存储过程?)
是否可以在SQL Server 2008中进行检查?MS是否在允许检查它的系统表中添加了一些新功能?
Answers:
SELECT name, create_date, modify_date
FROM sys.objects
WHERE type = 'P'
ORDER BY modify_date DESC
在type
一个函数FN
,而不是P
为程序。或者,您可以在名称列上进行过滤。
modify_date
可能会引起误解。例如,如果sys.sp_refreshsqlmodule
在模块上执行,modify_date
即使技术上模块代码未更改,也将更改。
AND name = 'specified procedure'
那里specified procedure
是你想要找的存储过程的名称。
尝试使用此存储过程:
SELECT name, create_date, modify_date
FROM sys.objects
WHERE type = 'P'
AND name = 'myProc'
我发现这被列为新技术
这很详细
SELECT * FROM INFORMATION_SCHEMA.ROUTINES
WHERE ROUTINE_TYPE = N'PROCEDURE' and ROUTINE_SCHEMA = N'dbo'
order by LAST_ALTERED desc
SELECT * FROM INFORMATION_SCHEMA.ROUTINES
WHERE ROUTINE_TYPE = N'PROCEDURE' and ROUTINE_SCHEMA = N'dbo'
order by CREATED desc
SELECT * FROM INFORMATION_SCHEMA.ROUTINES
WHERE ROUTINE_TYPE = N'FUNCTION' and ROUTINE_SCHEMA = N'dbo'
order by LAST_ALTERED desc
SELECT * FROM INFORMATION_SCHEMA.ROUTINES
WHERE ROUTINE_TYPE = N'FUNCTION' and ROUTINE_SCHEMA = N'dbo'
order by CREATED desc
对于SQL 2000,我将使用:
SELECT name, crdate, refdate
FROM sysobjects
WHERE type = 'P'
ORDER BY refdate desc
您可以将其用于检查修改日期,functions
并按日期stored procedures
一起排序:
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
要么 :
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
结果将是这样的:
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