SHOW CONSTRAINTS

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

Required privileges

The user must have any privilege on the target table.

Aliases

SHOW CONSTRAINT is an alias for SHOW CONSTRAINTS.

Synopsis

SHOWCONSTRAINTCONSTRAINTSFROMtable_name

Parameters

ParameterDescription
table_nameThe name of the table for which to show constraints.

Response

The following fields are returned for each constraint.

FieldDescription
table_nameThe name of the table.
constraint_nameThe name of the constraint.
constraint_typeThe type of constraint.
detailsThe definition of the constraint, including the column(s) to which it applies.
validatedWhether values in the column(s) match the constraint.

Example

  1. > CREATE TABLE orders (
  2. id INT PRIMARY KEY,
  3. date TIMESTAMP NOT NULL,
  4. priority INT DEFAULT 1,
  5. customer_id INT UNIQUE,
  6. status STRING DEFAULT 'open',
  7. CHECK (priority BETWEEN 1 AND 5),
  8. CHECK (status in ('open', 'in progress', 'done', 'cancelled')),
  9. FAMILY (id, date, priority, customer_id, status)
  10. );
  1. > SHOW CONSTRAINTS FROM orders;
  1. +------------+------------------------+-----------------+--------------------------------------------------------------------------+-----------+
  2. | table_name | constraint_name | constraint_type | details | validated |
  3. +------------+------------------------+-----------------+--------------------------------------------------------------------------+-----------+
  4. | orders | check_priority | CHECK | CHECK (priority BETWEEN 1 AND 5) | true |
  5. | orders | check_status | CHECK | CHECK (status IN ('open':::STRING, 'in progress':::STRING, | true |
  6. | | | | 'done':::STRING, 'cancelled':::STRING)) | |
  7. | orders | orders_customer_id_key | UNIQUE | UNIQUE (customer_id ASC) | true |
  8. | orders | primary | PRIMARY KEY | PRIMARY KEY (id ASC) | true |
  9. +------------+------------------------+-----------------+--------------------------------------------------------------------------+-----------+
  10. (4 rows)

See also

Was this page helpful?
YesNo