how to modify an existing check constraint?
You have to drop it and recreate it, but you don't have to incur the cost of revalidating the data if you don't want to.
alter table t drop constraint ck ;
alter table t add constraint ck check (n < 0) enable novalidate;
The enable novalidate
clause will force inserts or updates to have the constraint enforced, but won't force a full table scan against the table to verify all rows comply.
Create a new constraint first and then drop the old one.
That way you ensure that:
- constraints are always in place
- existing rows do not violate new constraints
- no illegal INSERT/UPDATEs are attempted after you drop a constraint and before a new one is applied.