IN-Decent

Re-decentralizing internet with free software

List Tables That Have a Specific Column in MySQL

Posted at — Jun 26, 2021

There are times when you are working with an unknown MySQL database schema, and you want to find out which tables are using a specific column in the database.

This can be easily found using data in information_schema database using below query,

SELECT t.table_schema AS database_name,t.table_name AS table_name
FROM information_schema.columns c, information_schema.tables t
WHERE t.table_schema = c.table_schema
AND t.table_name = c.table_name
AND t.table_type = 'BASE TABLE'
AND c.column_name = '<id>' -- << replace column name here
AND c.table_schema = '<db_name>' -- << replace db name here
ORDER BY t.table_schema, t.table_name;

References:

  1. Find tables with a specific column name in MySQL database