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?
views:
5859answers:
2
+3
A:
EDIT: why the formatting did not show? :\
SELECT TABLE_NAME, COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE column_name LIKE 'wild'
GSerg
2008-10-11 07:06:37
If there are multiple databases, add a WHERE TABLE_SCHEMA="" line also.
John Millikin
2008-10-11 07:08:45
Thanks John, how will the query if I need to get Table names which has columnA and ColumnB present?
Jobi Joy
2008-10-11 07:19:24
+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
2008-10-11 08:42:40