Thursday, May 21, 2009

Get Modified Date Of Stored Procedure

Original Link 

 
DECLARE @n_days INT
DECLARE @SCHEMA_NAME VARCHAR(25)
DECLARE @TableOrOrProcedre CHAR(1)
DECLARE @schema_id INT
SET @n_days = 10 --Give the number of days
SET @SCHEMA_NAME = 'Vehicle' --Name of schema
SET @schema_id = 5 -- Schema ID
SET @TableOrOrProcedre = 'p' -- T --> Table, P--> Procedure
--Get All the schema_id and its corresponding SCHEMA_NAME
SELECT DISTINCT SCHEMA_NAME(schema_id) AS SCHEMA_NAME ,
schema_id
FROM sys.objects
--IF we know the schema_id
SELECT name ,
create_date,
modify_date,
SCHEMA_NAME(schema_id) AS schema_name
FROM sys.objects AS SysObj
WHERE type = @TableOrOrProcedre
AND schema_id = @schema_id
AND modify_date > GETDATE() - @n_days
ORDER BY modify_date DESC
--IF we don't know the schema_id
SELECT name ,
create_date,
modify_date,
SCHEMA_NAME(SysObj.schema_id) AS schema_name
FROM sys.objects AS SysObj
INNER JOIN
(SELECT DISTINCT SCHEMA_NAME(schema_id) AS SCHEMA_NAME ,
schema_id
FROM sys.objects
) AS GetSchemaName
ON GetSchemaName.schema_id = SysObj.schema_id
WHERE type = @TableOrOrProcedre
AND GetSchemaName.SCHEMA_NAME = @SCHEMA_NAME
AND modify_date > GETDATE() - @n_days
ORDER BY modify_date DESC

No comments: