SQL Tips and Tricks

Find Column Used in Stored Procedure – Search Stored Procedure for Column Name. Also Search Stored Procedure Code and Stored Procedure Text

SELECT obj.NAME SPName

,com.TEXT SPText

FROM sys.syscomments com

INNER JOIN sys.objects obj ON com.Id = obj.OBJECT_ID

WHERE com.TEXT LIKE ‘%Column Name%’

AND TYPE = ‘P’

Find Column Used in Tables – Search Tables for Column Name

SELECT COLUMN_NAME

,TABLE_NAME

FROM INFORMATION_SCHEMA.COLUMNS

WHERE COLUMN_NAME LIKE ‘%Column Name%’

Find Stored Procedure Related to Table in Database – Search in All Stored Procedure

SELECT DISTINCT obj.NAME

,obj.xtype

FROM syscomments com

INNER JOIN sysobjects obj ON com.id = obj.id

WHERE com.TEXT LIKE ‘%Table Name %’

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s