Lesson 1 · Relational Modelling
FSA · Session 1
After this lesson, you can:
What the domain talks about
erDiagram
AUTHOR ||--o{ BOOK_AUTHOR : "1-n writes"
BOOK ||--o{ BOOK_AUTHOR : "1-n is written by"
BOOK ||--o{ LOAN : "1-n is lent as"
A member borrows a book on a date and returns it by a due date.
Member: it has facts of its own. The dates are facts about a loan.
How a row is found again
Every table has one primary key, chosen from its candidates
Candidate
Primary
Foreign
Any column set that identifies a row uniquely, such as isbn.
The candidate you choose to identify rows. It never changes.
A column that holds another table's primary key.
CREATE TABLE book (
isbn CHAR(13) PRIMARY KEY,
title TEXT NOT NULL
);
A reissued ISBN breaks every loan that points at it:
| loan | book_isbn |
|---|---|
| 1042 | 9780134685991 |
| 1043 | 9780134685991 |
CREATE TABLE book (
id BIGINT PRIMARY KEY,
isbn CHAR(13) NOT NULL UNIQUE,
title TEXT NOT NULL
);
Loans point at the id, which never changes:
| loan | book_id |
|---|---|
| 1042 | 7 |
| 1043 | 7 |
The member table is keyed on email, and every loan points at it:
| member.email (PK) | name |
|---|---|
| ana@mail.vn | Ana Tran |
| binh@mail.vn | Binh Le |
| loan | member_email | due |
|---|---|---|
| 1042 | ana@mail.vn | 2026-10-15 |
| 1043 | ana@mail.vn | 2026-10-22 |
| 1044 | binh@mail.vn | 2026-10-22 |
Ana changes her email. What happens to her two loans?
No. Emails change. Keep it UNIQUE and add a surrogate id.
Each fact stored once
1NF
One value per cell: no lists packed into a column.
2NF
Every column depends on the whole key, not part of it.
3NF
No column depends on another non-key column.
CREATE TABLE book (
id BIGINT PRIMARY KEY,
authors TEXT
);
Two authors in one cell: no join can find either.
| id | authors |
|---|---|
| 7 | Ana Tran, Binh Le |
CREATE TABLE book_author (
book_id BIGINT
REFERENCES book(id),
author_id BIGINT
REFERENCES author(id),
PRIMARY KEY (book_id,
author_id)
);
loan(id, book_id, book_title, due_date), with three of its rows:
| id | book_id | book_title | due_date |
|---|---|---|---|
| 1042 | 7 | Database Design | 2026-10-15 |
| 1043 | 7 | Database Design | 2026-10-22 |
| 1051 | 9 | SQL in Practice | 2026-10-29 |
Which normal form does it break, and which column is the clue?
3NF: book_title depends on book_id, not on the loan.