Sunday, 22 May 2022

Find all tables containing particular column

 

In this article, I am explaining how to find all tables containing a particular column of SQL statements.

Search Tables:

SELECT c.name  AS 'ColumnName' ,t.name AS 'TableName'

FROM sys.columns c

JOIN sys.tables  t   ON c.object_id = t.object_id

WHERE c.name LIKE '%my_column_name%'

ORDER BY TableName,ColumnName


Search Tables & Views:

SELECT  COLUMN_NAME AS 'ColumnName' ,TABLE_NAME AS  'TableName'

FROM  INFORMATION_SCHEMA.COLUMNS

WHERE  COLUMN_NAME LIKE '%MyName%'

ORDER BY TableName, ColumnName

No comments:

Post a Comment