How Do I Determine All Foreign Key Constraints Linked to a Table or Column in MySQL?
This question has been raised previously for Oracle, and here is the solution for MySQL:
To list foreign key constraints pointing to a specific table, use the following query:
SELECT TABLE_NAME,COLUMN_NAME,CONSTRAINT_NAME, REFERENCED_TABLE_NAME,REFERENCED_COLUMN_NAME FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE REFERENCED_TABLE_SCHEMA = (SELECT DATABASE()) AND REFERENCED_TABLE_NAME = '<table_name>' \G
To list foreign key constraints pointing to a specific column, alter the query like this:
SELECT TABLE_NAME,COLUMN_NAME,CONSTRAINT_NAME, REFERENCED_TABLE_NAME,REFERENCED_COLUMN_NAME FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE REFERENCED_TABLE_SCHEMA = (SELECT DATABASE()) AND REFERENCED_TABLE_NAME = '<table_name>' AND REFERENCED_COLUMN_NAME = '<column_name>' \G
Just substitute '
The above is the detailed content of How Can I Find All Foreign Key Constraints Referencing a MySQL Table or Column?. For more information, please follow other related articles on the PHP Chinese website!