Lesson 2.2

Constraints, keys, and integrity

Constraints are guarantees the database keeps even when a buggy deploy does not. Foreign keys, uniqueness, and checks belong in the schema.

Duration
4m
Level
Intermediate
Students
9.4k students

Overview

Constraints are guarantees the database keeps even when a buggy deploy does not. Foreign keys, uniqueness, and checks belong in the schema.

In this lesson you will:

  • Enforce relationships with foreign keys
  • Use unique and check constraints as invariants
  • Choose delete behaviour deliberately

Resources

PostgreSQL documentation

The official reference for the tools used in this lesson.