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 →

Related concepts

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.