All Known Implementing Classes:
Check, ForeignKey, PrimaryKey, Unique

@Evolving public interface Constraint
A constraint that restricts states of data in a table.
Since:
4.1.0
  • Method Details

    • name

      String name()
      Returns the name of this constraint.
    • enforced

      boolean enforced()
      Indicates whether this constraint is actively enforced. If enforced, data modifications that violate the constraint fail with a constraint violation error.
    • validationStatus

      Constraint.ValidationStatus validationStatus()
      Indicates whether the existing data in the table satisfies this constraint. The constraint can be valid (the data is guaranteed to satisfy the constraint), invalid (some records violate the constraint), or unvalidated (the validity is unknown). The validation status is usually managed by the system and can't be modified by the user.
    • rely

      boolean rely()
      Indicates whether this constraint is assumed to hold true if the validity is unknown. Unlike the validation status, this flag is usually provided by the user as a hint to the system.
    • toDDL

      String toDDL()
      Returns the definition of this constraint in the DDL format.
    • toDescription

      String toDescription()
      Returns the constraint description for DESCRIBE TABLE output, excluding the constraint name (shown separately).
    • check

      static Check.Builder check(String name)
      Instantiates a builder for a CHECK constraint.
      Parameters:
      name - the constraint name
      Returns:
      a CHECK constraint builder
    • unique

      static Unique.Builder unique(String name, NamedReference[] columns)
      Instantiates a builder for a UNIQUE constraint.
      Parameters:
      name - the constraint name
      columns - columns that comprise the unique key
      Returns:
      a UNIQUE constraint builder
    • primaryKey

      static PrimaryKey.Builder primaryKey(String name, NamedReference[] columns)
      Instantiates a builder for a PRIMARY KEY constraint.
      Parameters:
      name - the constraint name
      columns - columns that comprise the primary key
      Returns:
      a PRIMARY KEY constraint builder
    • foreignKey

      static ForeignKey.Builder foreignKey(String name, NamedReference[] columns, Identifier refTable, NamedReference[] refColumns)
      Instantiates a builder for a FOREIGN KEY constraint.
      Parameters:
      name - the constraint name
      columns - the referencing columns
      refTable - the referenced table identifier
      refColumns - the referenced columns in the referenced table
      Returns:
      a FOREIGN KEY constraint builder