Find tables that contain column name

The following script is used when I need to perform a search to find tables that contain a column name.

-- Use Control+Shift+M to specify a value column name

SELECT    TABLE_SCHEMA + '.' + TABLE_NAME
FROM    INFORMATION_SCHEMA.COLUMNS
WHERE    COLUMN_NAME = N'<column_name,varchar,(column_name)>'

or you can also use the following query.. 

-- Use Control+Shift+M to specify a value column name

SELECT sc.[name] AS column_name, so.[name] AS [TABLE]
FROM syscolumns sc
INNER JOIN sysobjects so ON sc.id=so.id
WHERE sc.[name] LIKE N'<column_name,varchar,(column_name)>'
AND so.xtype = 'U'

I

Leave a Reply

Your email address will not be published. Required fields are marked *

*

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>