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.
New in v19.1: This command can be combined with other
ALTER TABLE commands in a single statement. For a list of commands that can be combined, see
ALTER TABLE. For a demonstration, see Add and rename columns atomically.
The user must have the
CREATE privilege on the table.
||The name of the table in which the constraint you'd like to validate lives.|
||The name of the constraint on
Viewing schema changes
This schema change statement is registered as a job. You can view long-running jobs with
> ALTER TABLE orders ADD CONSTRAINT customer_fk FOREIGN KEY (customer_id) REFERENCES customers (id) ON DELETE CASCADE;
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;
If present in a
CREATE TABLE statement, the table is considered validated because an empty table trivially meets its constraints.