tags:

views:

5859

answers:

2

I have 2-3 different column names that I want to look up in the entire DB and list out all tables which have those columns. Any easy script?

+3  A: 

EDIT: why the formatting did not show? :\

SELECT TABLE_NAME, COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE column_name LIKE 'wild'
GSerg
If there are multiple databases, add a WHERE TABLE_SCHEMA="" line also.
John Millikin
Thanks John, how will the query if I need to get Table names which has columnA and ColumnB present?
Jobi Joy
+15  A: 

To get all tables with columns 'columnA' and 'ColumnB' in the database 'YourDatabase'

SELECT DISTINCT TABLE_NAME 
    FROM INFORMATION_SCHEMA.COLUMNS
    WHERE COLUMN_NAME IN ('columnA','ColumnB')
        AND TABLE_SCHEMA='YourDatabase';
Ken