PostgreSQL Cheat Sheet/Add check constraint

Add a named CHECK constraint.

Section: Schemas, Tables, and Core DDL

Add check constraint

sql
sql
ALTER TABLE orders ADD CONSTRAINT orders_total_nonnegative CHECK (total_amount >= 0);
Explanation

See summary for usage details.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Schemas, Tables, and Core DDL
Set NOT NULL
Enforce non-nullability on a column.
OpenIn sheetsqlsame section
Create table
Create a basic table with primary key and defaults.
OpenIn sheetsqlsame section
Create identity column
Use a SQL-standard identity column instead of serial.
OpenIn sheetsqlsame section
Add column
Add a nullable column to an existing table.
OpenIn sheetsqlsame section
Set column default
Change a column default value.
OpenIn sheetsqlsame section
Rename table
Rename a relation without recreating it.
OpenIn sheetsqlsame section