Nov 1, 2018

How to get all foreign keys to a table or column in MySQL

For a table
select
  TABLE_NAME,COLUMN_NAME,CONSTRAINT_NAME, REFERENCED_TABLE_NAME,REFERENCED_COLUMN_NAME
from INFORMATION_SCHEMA.KEY_COLUMN_USAGE
where
  REFERENCED_TABLE_NAME = '<table>';
for a column, the same but add an and for the REFERENCED_COLUMN_NAME.