The SHOW CONSTRAINTS statement lists all named constraints as well as any unnamed CHECK constraints on a table.

The SHOW CONSTRAINTS statement is under development; the exact output will continue to change.

Required Privileges

The user must have any privilege on the target table.

Aliases

SHOW CONSTRAINT is an alias for SHOW CONSTRAINTS.

Synopsis

SHOW CONSTRAINTS FROM table_name

Parameters

Parameter Description
table_name The name of the table for which to show constraints.

Response

The following fields are returned for each constraint.

The SHOW CONSTRAINTS statement is under development; the exact output will continue to change.
Field Description
Table The name of the table.
Name The name of the constraint.
Type The type of constraint.
Column(s) The column(s) to which the constraint applies. For CHECK constraints, column information will be in Details and this field will be NULL.
Details The conditions for a CHECK constraint.

Example

> 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



Yes No