TABLE_CONSTRAINTS

TABLE_CONSTRAINTS 表描述了哪些表具有约束(constraint)以及相关信息。

  1. DESC INFORMATION_SCHEMA.table_constraints;
  1. +--------------------+--------+------+------+---------+---------------+
  2. | Column | Type | Key | Null | Default | Semantic Type |
  3. +--------------------+--------+------+------+---------+---------------+
  4. | constraint_catalog | String | | NO | | FIELD |
  5. | constraint_schema | String | | NO | | FIELD |
  6. | constraint_name | String | | NO | | FIELD |
  7. | table_schema | String | | NO | | FIELD |
  8. | table_name | String | | NO | | FIELD |
  9. | constraint_type | String | | NO | | FIELD |
  10. | enforced | String | | NO | | FIELD |
  11. +--------------------+--------+------+------+---------+---------------+

表中的列:

  • CONSTRAINT_CATALOG: 约束所属 catalog 的名称。此值始终为 def
  • CONSTRAINT_SCHEMA: 约束所属数据库的名称。
  • CONSTRAINT_NAME: 约束的名称,可以是 TIME INDEXPRIMARY
  • TABLE_NAME: 表的名称。
  • CONSTRAINT_TYPE: 约束的类型。值可以是 TIME INDEXPRIMARY KEYTIME INDEXPRIMARY KEY 信息类似于 SHOW INDEX 语句的执行结果。
  • enforced: 不支持 CHECK 约束,此值始终为 YES
  1. select * from INFORMATION_SCHEMA.table_constraints WHERE table_name = 'monitor'\G;

输出结果:

  1. *************************** 1. row ***************************
  2. constraint_catalog: def
  3. constraint_schema: public
  4. constraint_name: TIME INDEX
  5. table_schema: public
  6. table_name: monitor
  7. constraint_type: TIME INDEX
  8. enforced: YES
  9. *************************** 2. row ***************************
  10. constraint_catalog: def
  11. constraint_schema: public
  12. constraint_name: PRIMARY
  13. table_schema: public
  14. table_name: monitor
  15. constraint_type: PRIMARY KEY
  16. enforced: YES