Skip to the workspace
Pebellslearn by building
Database Fundamentals  ›  Lesson

Database Design Basics — One Fact, One Place

Database Design Basics 14 minGood relational design stores each fact once, gives every table a primary key, and links tables with foreign keys instead of copying data.

aspnet core / Database Design Basics — One Fact, One Place

Explore each scene at your own pace.

01 · The rule

The rule

Database Design Basics — One Fact, One Place

The first sketch of ReadingRoom was one wide table, like a spreadsheet: every loan row carried the member's name and email and the book's title and author. It worked until a member changed their email and half their rows still showed the old one. Design is about making that kind of mistake impossible.

The rule

Store each fact once; point to it with a key.

Three ideas carry most of the weight:

  • A primary key uniquely identifies each row, usually an Id column. It never changes and never repeats.
  • A foreign key is a column holding another table's primary key: Loans.MemberId points at Members.Id.
  • Normalisation means splitting data so each fact lives in exactly one row. If you see the same value copied down a column, it probably belongs in its own table.

Before and after:

LoanId MemberName MemberEmail BookTitle DueDate
1 Asha asha@old.example Dune 2025-03-01
2 Asha asha@old.example Emma 2025-03-09

becomes Members(Id, Name, Email), Books(Id, Title, Author) and Loans(Id, MemberId, BookId, DueDate). Asha's email now lives in one row.

Relationships come in three shapes:

  • One-to-many — one member has many loans. The foreign key sits on the "many" side (Loans.MemberId).
  • Many-to-many — members borrow many books; books go to many members. A middle table (Loans) holds pairs of keys.
  • One-to-one — a member has one library card record. Rare; often just columns on the same table.
Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.