IT lexicon › Database › Constraint

Constraint

Database På svenska → Updated: 2026-11-10

A rule that the database enforces to guarantee data remains valid at all times.

A constraint is a restriction declaring which value combinations are allowed in a table. Examples include PRIMARY KEY (no row can have the same key), UNIQUE (no duplicates), FOREIGN KEY (value must exist in another table), and CHECK (value must satisfy a condition). The database automatically enforces these rules on insert and update — any attempt to violate a constraint results in an error.

Constraints are the foundation of data integrity: they prevent careless mistakes like storing a null in a required column or an age value of -5. Without constraints, the application must validate everything itself, which leads to bugs and inconsistencies when multiple programs access the same database.

← Back to the lexicon