PostgreSQL for Developers
LESSON 2.2

Constraints, keys, and integrity

Learn key techniques and workflows in PostgreSQL for Developers.

3m
intermediate
9,433 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

Pro Tip

Use caching and revalidation wisely to ensure your app stays fast and data remains fresh without unnecessary requests.

Resources