List all tables containing a given column name

smokinguns picture smokinguns · Feb 8, 2010 · Viewed 20.3k times · Source

How do a I list all tables containing a given column name? I'm using Mysql version 4.1.13-nt-log. I know versions less than 5 dont have an information_scheme DB.

Answer

Ed Massey picture Ed Massey · May 27, 2012

Find all tables and columns where column names are like the search term:

SELECT DISTINCT TABLE_NAME, COLUMN_NAME 
FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME LIKE '%partial_column_name%'
    AND TABLE_SCHEMA='YourDatabase';