Skip to content

Latest commit

 

History

History
59 lines (49 loc) · 3.21 KB

information-schema-table-constraints.md

File metadata and controls

59 lines (49 loc) · 3.21 KB
title summary aliases
TABLE_CONSTRAINTS
了解 information_schema 表 `TABLE_CONSTRAINTS`。
/docs-cn/dev/information-schema/information-schema-table-constraints/

TABLE_CONSTRAINTS

TABLE_CONSTRAINTS 表记录了表的约束信息。

{{< copyable "sql" >}}

USE information_schema;
DESC table_constraints;
+--------------------+--------------+------+------+---------+-------+
| Field              | Type         | Null | Key  | Default | Extra |
+--------------------+--------------+------+------+---------+-------+
| CONSTRAINT_CATALOG | varchar(512) | YES  |      | NULL    |       |
| CONSTRAINT_SCHEMA  | varchar(64)  | YES  |      | NULL    |       |
| CONSTRAINT_NAME    | varchar(64)  | YES  |      | NULL    |       |
| TABLE_SCHEMA       | varchar(64)  | YES  |      | NULL    |       |
| TABLE_NAME         | varchar(64)  | YES  |      | NULL    |       |
| CONSTRAINT_TYPE    | varchar(64)  | YES  |      | NULL    |       |
+--------------------+--------------+------+------+---------+-------+
6 rows in set (0.00 sec)

{{< copyable "sql" >}}

SELECT * FROM table_constraints WHERE constraint_type='UNIQUE';
+--------------------+--------------------+-------------------------+--------------------+-------------------------------------+-----------------+
| CONSTRAINT_CATALOG | CONSTRAINT_SCHEMA  | CONSTRAINT_NAME         | TABLE_SCHEMA       | TABLE_NAME                          | CONSTRAINT_TYPE |
+--------------------+--------------------+-------------------------+--------------------+-------------------------------------+-----------------+
| def                | mysql              | name                    | mysql              | help_topic                          | UNIQUE          |
| def                | mysql              | tbl                     | mysql              | stats_meta                          | UNIQUE          |
| def                | mysql              | tbl                     | mysql              | stats_histograms                    | UNIQUE          |
| def                | mysql              | tbl                     | mysql              | stats_buckets                       | UNIQUE          |
| def                | mysql              | delete_range_index      | mysql              | gc_delete_range                     | UNIQUE          |
| def                | mysql              | delete_range_done_index | mysql              | gc_delete_range_done                | UNIQUE          |
| def                | PERFORMANCE_SCHEMA | SCHEMA_NAME             | PERFORMANCE_SCHEMA | events_statements_summary_by_digest | UNIQUE          |
+--------------------+--------------------+-------------------------+--------------------+-------------------------------------+-----------------+
7 rows in set (0.01 sec)

TABLE_CONSTRAINTS 表中列的含义如下:

  • CONSTRAINT_CATALOG:约束所属的目录的名称。这个值总是 def
  • CONSTRAINT_SCHEMA:约束所属的数据库的名称。
  • CONSTRAINT_NAME:约束的名称。
  • TABLE_NAME:表的名称。
  • CONSTRAINT_TYPE:约束的类型。取值可以是 UNIQUEPRIMARY KEY 或者 FOREIGN KEYUNIQUEPRIMARY KEY 信息与 SHOW INDEX 语句的执行结果类似。