Computer >> 컴퓨터 >  >> 프로그램 작성 >> MySQL

MySQL에서 외래 키 제약 조건 목록 가져오기


테이블 수가 많은 "비즈니스" 데이터베이스가 있다고 가정해 보겠습니다. 외래 키 제약 조건만 표시하려면 다음 쿼리를 사용하십시오. -

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)