FirstSearch Blue

Find Everything You Need On Your First Search

Article

MySQL See all columns and tables that foreign key to a table or column

March 28, 2014 Updated February 19, 2017 1 min read test

mysql foreign keyIf you're trying to understand how an existing database has been setup it can be very useful to see all of the tables/columns that foreign key into some other table/column.

use INFORMATION_SCHEMA;
select TABLE_NAME,COLUMN_NAME,CONSTRAINT_NAME,
REFERENCED_TABLE_NAME,REFERENCED_COLUMN_NAME from KEY_COLUMN_USAGE where
REFERENCED_TABLE_NAME = 'your_table_name'
AND REFERENCED_COLUMN_NAME = 'your_column_name'

Conversation

Comments

Historic WordPress comments were imported into D1. New submissions stay in review until approved.

Published comments

Loading comments…