TABLE_ CONSTRAINTS view¶
This Information Schema view displays a row for each table constraint that is defined in the specified (or current) database. This view returns information about the following constraint types:
- PRIMARY KEY
- FOREIGN KEY
- UNIQUE
For general information about constraints, see Constraints.
- See also:
Columns¶
| Column Name | Data Type | Description |
|---|---|---|
| CONSTRAINT_CATALOG | VARCHAR | Database that the constraint belongs to |
| CONSTRAINT_SCHEMA | VARCHAR | Schema that the constraint belongs to |
| CONSTRAINT_NAME | VARCHAR | Name of the constraint |
| TABLE_CATALOG | VARCHAR | Name of the database of the current table |
| TABLE_SCHEMA | VARCHAR | Name of the schema of the current table |
| TABLE_NAME | VARCHAR | Name of the current table |
| CONSTRAINT_TYPE | VARCHAR | Type of the constraint |
| IS_DEFERRABLE | VARCHAR | Whether evaluation of the constraint can be deferred |
| INITIALLY_DEFERRED | VARCHAR | Whether evaluation of the constraint is deferrable and initially deferred |
| ENFORCED | VARCHAR | Whether the constraint is enforced |
| COMMENT | VARCHAR | Comment for this constraint |
| CREATED | TIMESTAMP_LTZ | Creation time of the constraint |
| LAST_ALTERED | TIMESTAMP_LTZ | Date and time the object was last altered by a DML, DDL, or background metadata operation. See Usage Notes. |
| RELY | VARCHAR | Whether a constraint in NOVALIDATE mode is taken into account during query rewrite. For details, see Constraint properties. |
Usage notes¶
- The view only displays objects for which the current role for the session has been granted access privileges.
-
The LAST_ALTERED column is updated when the following operations are performed on an object:
- DDL operations.
- DML operations (for tables only). This column is updated even when no rows are affected by the DML statement.
- Background maintenance operations on metadata performed by Snowflake.
Example¶
Create a hybrid table with a multi-column PRIMARY KEY constraint and a comment on the constraint. Query the view to get information about the constraint.
Return a list of constraints on all tables that have names beginning with HT: