Skip to main content

TABLE_CONSTRAINTS

Preview

This feature is in Public Preview.

Applies to: check marked yes Databricks SQL check marked yes Databricks Runtime 11.3 LTS and above check marked yes Unity Catalog only

INFORMATION_SCHEMA.TABLE_CONSTRAINTS contains metadata for all primary and foreign key constraints within the catalog.

The rows returned are limited to the tables the user has permission to interact with.

Definition

The TABLE_CONSTRAINTS relation contains the following columns:

NameData typeNullableStandardDescription
CONSTRAINT_CATALOGSTRINGNoYesCatalog containing the constraint.
CONSTRAINT_SCHEMASTRINGNoYesSchema containing the constraint.
CONSTRAINT_NAMESTRINGNoYesName of the constraint.
TABLE_CATALOGSTRINGNoYesCatalog containing the table.
TABLE_SCHEMASTRINGNoYesSchema containing the table.
TABLE_NAMESTRINGNoYesName of the table in which the constraint is defined.
CONSTRAINT_TYPESTRINGNoYesOne of 'CHECK', 'PRIMARY KEY', 'FOREIGN KEY'
IS_DEFERRABLESTRINGNoYesAlways’YES’. Reserved for future use.
INITIALLY_DEFERREDSTRINGNoYesAlways 'YES'. Reserved for future use.
ENFORCEDSTRINGNoYes'YES' if constraint is enforced, 'NO' otherwise.
COMMENTSTRINGYesNoOptional description of the constraint.

Constraints

The following constraints apply to the TABLE_CONSTRAINTS relation:

ClassNameColumn ListDescription
Primary keyTAB_CONS_PKCONSTRAINT_CATALOG, CONSTRAINT_SCHEMA, CONSTRAINT_NAMEUniquely identifies the relation.
Foreign keyTAB_CONS_TABLES_FKTABLE_CATALOG, TABLE_SCHEMA, TABLE_NAMEReferences TABLES_PK

Examples

SQL
> SELECT constraint_name
FROM information_schema.constraint_table_usage
WHERE table_schema = 'information_schema'
AND table_name = 'tables'
AND constraint_type = 'CHECK'