Check constraint
A CHECK constraint is a database rule requiring each inserted or updated row or constrained value to satisfy a specified Boolean condition.
Just Use Postgres!
A check constraint is a database rule that rejects a row when a specified Boolean condition is false.
- How it is used
- Enforces application data-integrity rules at the PostgreSQL database level.
- How deep it goes
- Defines custom Boolean conditions and demonstrates CREATE TABLE, ALTER TABLE, inspection, and rejected writes.
- Examples
- Uses catalog categories, nonnegative stock, positive prices, review ranks, and pending-or-ordered order statuses.
- What you can do after
- Operate/configure PostgreSQL tables by declaring, adding, inspecting, and testing check constraints.
Learn SQL in a Month of Lunches
A CHECK constraint is a database rule that permits a column value only when it satisfies a specified Boolean expression.
- How it is used
- Protects data integrity by limiting column values to those that satisfy specified expressions.
- How deep it goes
- Defines range, membership, and multi-column expressions, but does not develop complex constraint design beyond simple examples.
- Examples
- Uses shipment costs, shipment methods, payment years, and payment amounts as validation examples.
- What you can do after
- Build it from scratch by adding range, membership, and positive-value checks to CREATE TABLE definitions.
Read how Learn SQL in a Month of Lunches explains check constraint →
Related concepts
- constraintkind of · A constraint is a condition or rule that limits the permissible choices, states, actions, values, or solutions in a system or problem.
- expressionuses · An expression is a syntactic construct in a programming language that evaluates to a value or designates an object, and may also cause side effects.
- alter table commandused by · ALTER TABLE is an SQL data-definition statement that modifies the structure or properties of an existing table.
- data integrityuses · Data integrity is the property that data remains accurate, complete, consistent, and valid, with changes made only through authorized actions.
- membership operatorused by · A membership operator is a language construct that tests whether a specified value or property is present in a supported collection, range, or object.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

