chevron_left
General table Cookbook
0
0
0
new
Finding all tables with a specific column name in MySQL
Database
chevron_rightMySQL
chevron_rightCookbooks
chevron_rightTables Cookbooks
chevron_rightGeneral table Cookbook
schedule Jul 1, 2022
Last updated MySQL
Tags tocTable of Contents
expand_more It is possible to check for all tables within a database that contain a specific column name using the below:
SELECT DISTINCT TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNSWHERE COLUMN_NAME IN ('specific_column1')AND TABLE_SCHEMA='specific_database';
specific_column1
represents the column name you would like to check for.
specific_database
represents the database that tables you would like to search for reside in.
Example
To locate all tables containing the column student_id
within the people
database:
SELECT DISTINCT TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNSWHERE COLUMN_NAME IN ('student_id')AND TABLE_SCHEMA='people';
+----------------------+| TABLE_NAME |+----------------------+| copy_drivers_license || drivers_license || extracurricular || new_drivers_license || students || students_copy |+----------------------+
Published by Arthur Yanagisawa
Edited by 0 others
Did you find this page useful?
Ask a question or leave a feedback...
0
0
0
Enjoy our search