Wednesday, July 18, 2012

Searching All Objects Which Uses A Particular Column

1) Search in Stored Procedure


SELECT obj.Name SPName, sc.TEXT SPText
FROM sys.syscomments sc
INNER JOIN sys.objects obj ON sc.Id = obj.OBJECT_ID
WHERE sc.TEXT LIKE '%' + 'Name Your Column Here' + '%'
AND TYPE = 'P'

2) Search in All Objects

This script search stored procedures, views, functions as well other objects.

-- Search in All Objects
SELECT OBJECT_NAME(OBJECT_ID),
definition
FROM sys.sql_modules
WHERE definition LIKE '%' +'Name Your Column Here' + '%'
GO

3) Search in Stored Procedure

This script search only stored procedure for specified column.

-- Search in Stored Procedure Only
SELECT DISTINCT OBJECT_NAME(OBJECT_ID),
object_definition(OBJECT_ID)
FROM sys.Procedures
WHERE object_definition(OBJECT_ID) LIKE '%' + 'Name Your Column Here' + '%'

No comments:

Post a Comment