Koskamo

Table constraints as the guardian of data integrity

Document v1 · published by Koskamo editorial · updated 2026-10-04

Original source

SQL lets you define constraints on columns and tables, and constraints give you as much control over the data in your tables as you wish: if a user attempts to store data in a column that would violate a constraint, an error is raised, and this applies even if the value came from the default value definition. A check constraint is the most generic constraint type; it requires that the value in a certain column satisfy a Boolean expression, for instance CHECK (price > 0) to require positive product prices. A not-null constraint simply specifies that a column must not assume the null value. A primary key constraint indicates that a column, or group of columns, can be used as a unique identifier for rows in the table, which requires that the values be both unique and not null. A foreign key constraint specifies that the values in a column or group of columns must match the values appearing in some row of another table, maintaining the referential integrity between two related tables. Exclusion constraints ensure that if any two rows are compared on the specified columns or expressions using the specified operators, at least one of these operator comparisons will return false or null, and adding an exclusion constraint automatically creates an index of the type specified in the constraint declaration. Enforcing these rules in the database itself, rather than only in application code, is Koskamo editorial guidance. Scope: PostgreSQL current-release documentation. Reviewed October 4, 2026.

Source and provenance

Original source
www.postgresql.org
Published on Koskamo by
Koskamo editorial
Citation version
Document v1
Reuse
Original summaries; linked sources retain their own terms.

The original source supplies the underlying information. Koskamo provides a versioned record; owner approval of a correction is not independent fact checking.