Note:
Cockroach Labs supports the current stable release and two releases prior. Therefore, this version will no longer be supported after the Spring 2019 release.

The VALIDATE CONSTRAINT statement is part of ALTER TABLE and checks whether values in a column match a constraint on the column.

This statement is especially useful after applying a constraint to an existing column via ADD CONSTRAINT. In this case, VALIDATE CONSTRAINT can be used to find values already in the column that do not match the constraint.

Required Privileges

The user must have the CREATE privilege on the table.

Synopsis

ALTER TABLE IF EXISTS table_name VALIDATE CONSTRAINT constraint_name

Parameters

Parameter Description
table_name The name of the table in which the constraint you'd like to validate lives.
constraint_name The name of the constraint on table_name you'd like to validate.

Examples

In ADD CONSTRAINT, we added a foreign key constraint like so:

ALTER TABLE orders ADD CONSTRAINT customer_fk FOREIGN KEY (customer_id) REFERENCES customers (id);

In order to ensure that the data added to the orders table prior to the creation of the customer_fk constraint conforms to that constraint, run the following:

ALTER TABLE orders VALIDATE CONSTRAINT customer_fk;
Note:
If present in a CREATE TABLE statement, the table is considered validated because an empty table trivially meets its constraints.

See Also



Yes No