List tables by foreign key in MySQL

1

How to identify tables that relate to one another, that is, tables that have a foreign key that references another table?

As the dummy example, I need a statement that shows the list of tables linked to the product table as output, in this case the tables item_product and stock .

    
asked by anonymous 21.03.2015 / 02:33

1 answer

2

You can get the list of foreign keys by passing a table with this query:

SELECT
   constraint_name as nome_restricao,
   column_name as coluna_estrangeira,
   table_name as tabela_estrangeira,
   referenced_table_name as tabela_origem, 
   referenced_column_name as coluna_origem

FROM information_schema.KEY_COLUMN_USAGE
WHERE REFERENCED_TABLE_NAME = 'produto'

MySQL - KEY_COLUMN_USAGE

MySQL - Information_schema

    
21.03.2015 / 03:56