Monday 18 June 2012

Find all Tables Containing a Column Name

    If you like to get all the tables in a database which contains a column name you specified, then write the below queries and get it easily:


SELECT  C.name AS ColName, T.name AS TableName
FROM    sys.columns C
        JOIN sys.tables T
        ON C.object_id = T.object_id
WHERE   C.name LIKE '%MyColName%'

--- Or...---

SELECT  COLUMN_NAME, TABLE_NAME
FROM   INFORMATION_SCHEMA.COLUMNS
WHERE   COLUMN_NAME LIKE '%MyColName%'








Reference: Govind Badkur(http://govindbadkur.blogspot.com)

No comments:

Post a Comment