我想找到我创建的存储过程,并且我想在特定日期(例如2012年9月27日(2012年9月27日))找到我在SQL Server中修改的存储过程。
是否有任何查询会列出在此日期创建和修改的这些程序?
答案 0 :(得分:65)
您可以在任何给定的SQL Server数据库中尝试此查询:
SELECT
name,
create_date,
modify_date
FROM sys.procedures
WHERE create_date = '20120927'
列出了名称,创建和最后修改日期 - 遗憾的是,它没有记录谁创建和/或修改了相关存储过程。
答案 1 :(得分:12)
这是“新学校”版本。
SELECT * FROM INFORMATION_SCHEMA.ROUTINES
WHERE ROUTINE_TYPE = N'PROCEDURE' and ROUTINE_SCHEMA = N'dbo'
and CREATED = '20120927'
答案 2 :(得分:4)
SELECT name
FROM sys.objects
WHERE type = 'P'
AND (DATEDIFF(D,modify_date, GETDATE()) < 7
OR DATEDIFF(D,create_date, GETDATE()) < 7)
答案 3 :(得分:1)
SELECT * FROM sys.objects WHERE type='p' ORDER BY modify_date DESC
SELECT name, create_date, modify_date
FROM sys.objects
WHERE type = 'P'
SELECT name, crdate, refdate
FROM sysobjects
WHERE type = 'P'
ORDER BY refdate desc
答案 4 :(得分:0)
修改了更多对象的第一个查询:表,视图,UDF,SP等。您可以添加自己的对象类型。
DECLARE @OldSchema AS VARCHAR(255);
DECLARE @NewSchema AS VARCHAR(255);
SET @OldSchema = 'dbo';
SET @NewSchema = 'new_dbo';
DECLARE @sql AS VARCHAR(MAX);
DECLARE @sqlTmp AS VARCHAR(MAX);
SET @sql = 'CREATE SCHEMA [' + @NewSchema + ']' + CHAR(13) + CHAR(10);
PRINT @sql;
DECLARE @a INT = 1;
WHILE ( @a < 1000000 )
BEGIN
SET @sqlTmp = '';
SELECT @sqlTmp = 'ALTER SCHEMA [' + @NewSchema + '] TRANSFER ['
+ s_name + '].[' + o_name + ']'
FROM ( SELECT s.name s_name ,
o.name o_name ,
ROW_NUMBER() OVER ( ORDER BY o.object_id ) r
FROM sys.objects o
JOIN sys.schemas s ON o.schema_id = s.schema_id
WHERE s.name = @OldSchema
AND o.type IN ( 'P', 'U', 'V', 'IF', 'TF', 'FN' )
) a
WHERE r = @a;
IF ( @@ROWCOUNT = 0 )
SET @a = 100000000;
SET @a = @a + 1;
SET @sql = @sql + COALESCE(@sqlTmp, '') + CHAR(13) + CHAR(10);
PRINT @sqlTmp;
END;
SET @sql = @sql + 'DROP SCHEMA [' + @OldSchema + ']';
PRINT 'DROP SCHEMA [' + @OldSchema + ']';
答案 5 :(得分:0)
对于SQL Server 2012:
SELECT name, modify_date, create_date, type
FROM sys.procedures
WHERE name like '%XXX%'
ORDER BY modify_date desc