Skip to content


AlterTableAddConstraintDeltaCommand is an AlterDeltaTableCommand.

AlterTableAddConstraintDeltaCommand is a RunnableCommand (Spark SQL) and IgnoreCachedData (Spark SQL).

Creating Instance

AlterTableAddConstraintDeltaCommand takes the following to be created:

  • DeltaTableV2
  • Constraint Name
  • Constraint SQL Expression (as a text)

AlterTableAddConstraintDeltaCommand is created when:

Executing Command

  sparkSession: SparkSession): Seq[Row]

run is part of the RunnableCommand (Spark SQL) abstraction.


run prints out the following INFO message to the logs:

Checking that [constraint] is satisfied for existing data. This will require a full table scan.

run requests the OptimisticTransaction for the DeltaLog to create a DataFrame (for the snapshot).

run uses where operator and counts the rows that do not match the constraint.

With no rows violating the check constraint, run requests the OptimisticTransaction to commit (with the new Metadata and a new AddConstraint).


run throws an AnalysisException when one or more rows violate the new constraint:

[num] rows in [tableName] violate the new CHECK constraint ([expr])
Back to top