liveBook · Manning

Check constraint

A CHECK constraint is a database rule requiring each inserted or updated row or constrained value to satisfy a specified Boolean condition.

How 2 Manning books explain it

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.

Read how Just Use Postgres! explains check constraint →

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

Related concepts

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.