Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL: How do I find out which tables reference a specific table?

People also ask

How do you find all tables that have foreign keys that reference particular table column?

To see foreign key relationships of a table: SELECT TABLE_NAME, COLUMN_NAME, CONSTRAINT_NAME, REFERENCED_TABLE_NAME, REFERENCED_COLUMN_NAME FROM INFORMATION_SCHEMA. KEY_COLUMN_USAGE WHERE REFERENCED_TABLE_SCHEMA = 'db_name' AND REFERENCED_TABLE_NAME = 'table_name';

How do I search a specific table in MySQL?

Find data across a MySQL connection by using the text search feature on any number of tables and schemas. From the schema tree, select the tables, schemas, or both to search and then right-click the highlighted items and click Search Data Table from the context menu.


select table_name
from information_schema.KEY_COLUMN_USAGE
where table_schema = 'my_database'
and referenced_table_name = 'my_table_here';

This works.


select table_name 
from information_schema.referential_constraints 
where referenced_table_name = 'parent table here';

If you have phpMyAdmin installed, you can use its designer feature to visualize table relationships.

enter image description here

To use the designer, select a database, then look for the Designer tab.