select* −>frominformation_schema.referential_constraints −>whereconstraint_schema='business';The following is the output to display only foreign key constraints-+------"/> select* −>frominformation_schema.referential_constraints −>whereconstraint_schema='business';The following is the output to display only foreign key constraints-+------">

Home  >  Article  >  Database  >  Get list of foreign key constraints in MySQL

Get list of foreign key constraints in MySQL

PHPz
PHPzforward
2023-08-31 11:53:10749browse

Get list of foreign key constraints in MySQL

Suppose we have a database "business" that contains multiple tables. If you want to display only foreign key constraints, use the following query -

mysql> select *
   −> from information_schema.referential_constraints
   −> where constraint_schema = 'business';

The following is the output to display only foreign key constraints -

+--------------------+-------------------+--------------------------+---------------------------+--------------------------+------------------------+--------------+-------------+-------------+-------------------+-----------------------+
| CONSTRAINT_CATALOG | CONSTRAINT_SCHEMA | CONSTRAINT_NAME          | UNIQUE_CONSTRAINT_CATALOG | UNIQUE_CONSTRAINT_SCHEMA | UNIQUE_CONSTRAINT_NAME | MATCH_OPTION | UPDATE_RULE | DELETE_RULE | TABLE_NAME       | REFERENCED_TABLE_NAME |
+--------------------+-------------------+--------------------------+---------------------------+--------------------------+------------------------+--------------+-------------+-------------+-------------------+-----------------------+
| def                | business          | ConstChild               | def                       | business                 | PRIMARY                | NONE         | NO ACTION   | NO ACTION | childdemo         | parentdemo |
| def                | business          | ConstFK                  | def                       | business                 | PRIMARY                | NONE         | NO ACTION   | NO ACTION | tblf | tblp |
| def                | business          | constFKPK                | def                       | business                 | PRIMARY                | NONE         | NO ACTION   | NO ACTION | foreigntable      | primarytable1 |
| def                | business          | FKConst                  | def                       | business                 | PRIMARY                | NONE         | NO ACTION   | NO ACTION | foreigntabledemo | primarytabledemo |
| def                | business          | primarytable1demo_ibfk_1 | def                       | business                 | PRIMARY                | NONE         | NO ACTION   | NO ACTION | primarytable1demo| foreigntable1 |
| def                | business          | StudCollegeConst         | def                       | business                 | PRIMARY                | NONE         | NO ACTION   | NO ACTION   | studentenrollment| college |
+--------------------+-------------------+--------------------------+---------------------------+--------------------------+------------------------+--------------+-------------+-------------+-------------------+-----------------------+
6 rows in set (0.07 sec)

The above is the detailed content of Get list of foreign key constraints in MySQL. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete