only My site

Tuesday, October 23, 2012

SQL Table and Stored Procedure List - Search using Keyword


SP List based on Keyword(table name, field name etc) Search


SELECT DISTINCT obj.Name SPName
FROM sys.syscomments sc
INNER JOIN sys.objects obj ON sc.Id = obj.OBJECT_ID
WHERE sc.TEXT LIKE '%' + 'Lead_Approver' + '%'
AND TYPE = 'P'

List tables based on column name search

SELECT name FROM sysobjects WHERE id IN ( SELECT id FROM syscolumns
WHERE name like '%Lead%' )

SP List with Created date and Modified date

SELECT name, create_date, modify_date
FROM sys.objects
WHERE type = 'P'

List All Stored Procedure Modified in Last N Days

SELECT name
FROM sys.objects
WHERE type = 'P'
AND DATEDIFF(D,modify_date, GETDATE()) < 7


SELECT name
FROM sys.objects
WHERE type = 'P'
AND DATEDIFF(D,create_date, GETDATE()) < 7

No comments: