.NET Programming With Me

MySQL: Find the source and destination of all foreign key constraints

We can easily find all foreign keys of a MySQL Database using this query.

SELECT referenced_table_name AS ParentTable,
       table_name            AS ChildTable,
       constraint_name       AS ConstraintName
FROM   information_schema.key_column_usage
WHERE  referenced_table_name IS NOT NULL
       AND table_schema = '<your_db_name>' -- optional
ORDER  BY referenced_table_name;

No comments: