Home / Blog / Post
Find Tables By Column Name In Mysql Database
Added on 21st January 2019 in Snippet

The following query allows you to identify tables which contain a specific column, this can be helpful when working with larger databases which reference common field names which are not actually foreign keys. An example of this would be a user_id which is used on a user table, and other tables which can be tied to a specific user.

SELECT DISTINCT TABLE_NAME 
FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME LIKE '%column_name%'
AND TABLE_SCHEMA=’database_name’;

Hi there, I am christopher shaw, a software developer form South Yorkshire, England.

I love tinkering with all things tech, and opened this website as a web presence for myself and a place to keep my notes and snippets. Hopefully you will find something here to help

Christopher Shaw