SHOW CONSTRAINTS 语句 用于列出表中所有命名 约束 和未命名的 Check 约束

Warning: SHOW CONSTRAINTS 语句功能还在开发中,还会持续更新。

所需权限

用户需具有目标表的任一 权限

Aliases

SHOW CONSTRAINTSHOW CONSTRAINTS的一个别名。

Synopsis

图片

Parameters

Parameter Description
table_name 表名

返回

下面是约束返回的字段。

Warning: SHOW CONSTRAINTS 语句功能还在开发中,还会持续更新。

Field Description
Table 表名
Name 约束名字
Type 约束类型
Column(s) 约束所使用的列。 对于 Check constraints,列信息在 Details中,本字段为 NULL
Details Check约束的条件

例子

> CREATE TABLE orders (
    id INT PRIMARY KEY,
    date TIMESTAMP NOT NULL,
    priority INT DEFAULT 1,
    customer_id INT UNIQUE,
    status STRING DEFAULT 'open',
    CHECK (priority BETWEEN 1 AND 5),
    CHECK (status in ('open', 'in progress', 'done', 'cancelled')),
    FAMILY (id, date, priority, customer_id, status)
);

> SHOW CONSTRAINTS FROM orders;
+--------+------------------------+-------------+---------------+--------------------------------------------------------+
| Table  |          Name          |    Type     |   Column(s)   |                        Details                         |
+--------+------------------------+-------------+---------------+--------------------------------------------------------+
| orders |                        | CHECK       | NULL          | status IN ('open', 'in progress', 'done', 'cancelled') |
| orders |                        | CHECK       | NULL          | priority BETWEEN 1 AND 5                               |
| orders | orders_customer_id_key | UNIQUE      | [customer_id] | NULL                                                   |
| orders | primary                | PRIMARY KEY | [id]          | NULL                                                   |
+--------+------------------------+-------------+---------------+--------------------------------------------------------+
(4 rows)

See Also