首页  >  文章  >  数据库  >  获取MySQL中的外键约束列表

获取MySQL中的外键约束列表

PHPz
PHPz转载
2023-08-31 11:53:10737浏览

获取MySQL中的外键约束列表

假设我们有一个包含多个表的数据库“business”。如果您只想显示外键约束,请使用以下查询 -

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

以下是仅显示外键约束的输出 -

+--------------------+-------------------+--------------------------+---------------------------+--------------------------+------------------------+--------------+-------------+-------------+-------------------+-----------------------+
| 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)

以上是获取MySQL中的外键约束列表的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文转载于:tutorialspoint.com。如有侵权,请联系admin@php.cn删除