TABLE_CONSTRAINTS

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

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)
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 语句的执行结果类似。

文档内容是否有帮助?