SHOW CONSTRAINTS

On this page Carat arrow pointing down
Warning:
As of April 12, 2019, CockroachDB v1.1 is no longer supported. For more details, refer to the Release Support Policy.

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

Warning:
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 CONSTRAINT 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.

Warning:
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 columns 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
On this page

Yes No