Databases

Lesson 1 · Relational Modelling

FSA · Session 1

After this lesson, you can:

Entities and relationships

What the domain talks about

Entities are nouns with facts

The sentence 'A member borrows a book' with member and book marked as nouns and borrows as the verb, each pointing down to an entity: member, loan and book

The catalogue, drawn

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"
Author, book, book_author and loan, each relationship labelled 1-n
Each label says the cardinality in words first.

Which of these is an entity?

A member borrows a book on a date and returns it by a due date.

Answer

Member: it has facts of its own. The dates are facts about a loan.

A library loan slip with four fields: member Ana Tran, book Database Design, borrowed 2026-10-01, due 2026-10-15

Keys

How a row is found again

Three kinds of key

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.

Prefer a surrogate key

CREATE TABLE book (
  isbn  CHAR(13) PRIMARY KEY,
  title TEXT NOT NULL
);

A reissued ISBN breaks every loan that points at it:

loanbook_isbn
10429780134685991
10439780134685991
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:

loanbook_id
10427
10437

Is an email a good primary key?

The member table is keyed on email, and every loan points at it:

member.email (PK)name
ana@mail.vnAna Tran
binh@mail.vnBinh Le
loanmember_emaildue
1042ana@mail.vn2026-10-15
1043ana@mail.vn2026-10-22
1044binh@mail.vn2026-10-22

Ana changes her email. What happens to her two loans?

Answer

No. Emails change. Keep it UNIQUE and add a surrogate id.

Normalization

Each fact stored once

Three normal forms, one rule each

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.

A list in a column breaks 1NF

CREATE TABLE book (
  id      BIGINT PRIMARY KEY,
  authors TEXT
);

Two authors in one cell: no join can find either.

idauthors
7Ana 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)
);

Which form does it break?

loan(id, book_id, book_title, due_date), with three of its rows:

idbook_idbook_titledue_date
10427Database Design2026-10-15
10437Database Design2026-10-22
10519SQL in Practice2026-10-29

Which normal form does it break, and which column is the clue?

Answer

3NF: book_title depends on book_id, not on the loan.