Skip to main content
Skip to main content

Manipulating Constraints

Constraints could be added, modified or deleted using following syntax:

ALTER TABLE [db].name [ON CLUSTER cluster] ADD CONSTRAINT [IF NOT EXISTS] constraint_name {CHECK|ASSUME} expression;
ALTER TABLE [db].name [ON CLUSTER cluster] MODIFY CONSTRAINT [IF EXISTS] constraint_name {CHECK|ASSUME} expression;
ALTER TABLE [db].name [ON CLUSTER cluster] DROP CONSTRAINT [IF EXISTS] constraint_name;

As with table creation, a constraint can be declared either as CHECK (enforced on INSERT) or as ASSUME (trusted by the optimizer without being checked). See constraints for the difference between the two.

MODIFY CONSTRAINT replaces the declaration of an existing constraint, keeping its position in the table definition. It can also change the constraint kind (for example, from CHECK to ASSUME). It is equivalent to dropping the constraint and adding it again with the new declaration. If the constraint does not exist, the query throws an error, unless IF EXISTS is specified.

See more on constraints.

Queries will add, change or remove metadata about constraints from table, so they are processed immediately.

Tip

Constraint check will not be executed on existing data if it was added or modified.

All changes on replicated tables are broadcast to ZooKeeper and will be applied on other replicas as well.