Integrity Constraints

Integrity constraints are rules enforced by the database to ensure data validity and consistency. They prevent invalid or inconsistent data and capture business rules.

  • Primary key
    Uniquely identifies a row and cannot be NULL.
  • Foreign key
    Enforces referential integrity between tables.
  • Unique
    Ensures column values are unique.
  • Not null
    Disallows NULL values in a column.
  • Check
    Enforces custom conditions or ranges on values.

Common Integrity Constraints

PRIMARY KEY

Declare the primary key of the relation. If multiple columns are used, they are declared as a composite primary key.

NOT NULL

Declare an attributes to be not null. Applied to primary keys automatically.

UNIQUE

Declare a column or set of columns to be unique. Can be null.

CHECK

Enforce custom conditions or ranges on values. All kinds of WHERE predicates are allowed with CHECK. Can refer multiple columns of a single table. Cannot reference other rows or other tables.

DEFAULT

Specify a default value for a column.

Referential Integrity

Enforce referential integrity between tables. Foreign keys must reference existing primary keys.

Written by September 13, 2026 1 min read
Was this helpful?