For each instance of MySql
there is a database called information_schema
. This database contains all the information of all the instance databases.
To recover all foreign keys, just make a SELECT
on the table REFERENTIAL_CONSTRAINTS
:
SELECT *
FROM information_schema.`REFERENTIAL_CONSTRAINTS`;
If you want to filter foreign keys from a specific table, add the clause WHERE
:
SELECT *
FROM information_schema.`REFERENTIAL_CONSTRAINTS` a
WHERE a.`CONSTRAINT_SCHEMA` = 'nome_do_banco' AND a.`TABLE_NAME` = 'nome_da_tabela'
There are many other useful things in this database, see the documentation.
Cool +1.......
– Wallace Maxters