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 →
Also covered in
What to know first
- char(n)CHAR(n) is a fixed-length SQL character-string data type whose values occupy the declared character length, typically with trailing-space padding.
- data integrityData integrity is the property of data being accurate, complete, consistent, and valid throughout its storage, processing, and transfer.
- SQLSQL is a standardized declarative language for defining, querying, and manipulating data in relational database systems.
Related concepts
- constraintkind of · A constraint is a condition or rule that restricts the permissible choices, states, actions, values, or solutions in a system or problem.
- expressionuses · An expression is a syntactically formed combination of values, names, operators, or other terms that denotes or evaluates to a value or result.
- 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 of data being accurate, complete, consistent, and valid throughout its storage, processing, and transfer.
- 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.
Questions about check constraint
What is check constraint?
A CHECK constraint is a database rule requiring each inserted or updated row or constrained value to satisfy a specified Boolean condition.
Which Manning books explain check constraint?
Just Use Postgres! and Learn SQL in a Month of Lunches.
What should I know before learning check constraint?
Manning books that teach check constraint usually introduce char(n), data integrity and SQL first.
What is the difference between check constraint and varchar(n)?
A CHECK constraint is a database rule requiring each inserted or updated row or constrained value to satisfy a specified Boolean condition. VARCHAR(n) is a PostgreSQL variable-length character data type that limits stored values to at most n characters.
What is check constraint a kind of?
Check constraint is a kind of constraint. A constraint is a condition or rule that restricts the permissible choices, states, actions, values, or solutions in a system or problem.
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.

