Alter table add check constraint to a table

PostreSQL tutorial – Add check constraint

Add check constraint to table

How to add check constraint to an existing table. Alter syntax and example.

Examples

Add check constraint to a table and all its children.

ALTER TABLE customers 
ADD CONSTRAINT ch_first_name 
CHECK (char_length(first_name) <= 20);

Add check constraint only to a table and not to its children.

ALTER TABLE customers 
ADD CONSTRAINT ch_first_name 
CHECK (char_length(first_name) <= 20) NO INHERIT;

Alter table |
Drop table