Final challenge: the library
After this: Find the repeated facts in a library's loans table, choose its keys and rules, and split it.
A small library keeps every loan in one table, loans_flat: who borrowed which book, the member's email, the book's author and the date. This challenge has five steps, and each step is scored on its own. You will spot the facts the table repeats, name the key of a loan, choose the rule that keeps emails apart, decide where the author goes, and write the key line of the new loans table. You can try as many times as you like, and hints work as they do in the lessons.
A library keeps every loan in one table. Which facts does it write more than once?
SELECT member, member_email, book, author, borrowedFROM loans_flatORDER BY borrowed;| member | member_email | book | author | borrowed |
|---|---|---|---|---|
| Ana | ana@mail.test | Dune | Herbert | 2026-10-01 |
| Ana | ana@mail.test | Emma | Austen | 2026-10-03 |
| Ben | ben@mail.test | Dune | Herbert | 2026-10-05 |
| Ben | ben@mail.test | Persuasion | Austen | 2026-10-06 |
| Cy | cy@mail.test | Emma | Austen | 2026-10-07 |
| Cy | cy@mail.test | Ulysses | Joyce | 2026-10-09 |
What should be the key of a loan: the columns that name one loan and can never repeat?
SELECT member, member_email, book, author, borrowedFROM loans_flatORDER BY borrowed;| member | member_email | book | author | borrowed |
|---|---|---|---|---|
| Ana | ana@mail.test | Dune | Herbert | 2026-10-01 |
| Ana | ana@mail.test | Emma | Austen | 2026-10-03 |
| Ben | ben@mail.test | Dune | Herbert | 2026-10-05 |
| Ben | ben@mail.test | Persuasion | Austen | 2026-10-06 |
| Cy | cy@mail.test | Emma | Austen | 2026-10-07 |
| Cy | cy@mail.test | Ulysses | Joyce | 2026-10-09 |
After the split, members has the columns id, name and email. Which rule stops two members from sharing one email?
In loans_flat, the author depends on the book alone. Which rule does that break, and where does the author go?
SELECT member, member_email, book, author, borrowedFROM loans_flatORDER BY borrowed;| member | member_email | book | author | borrowed |
|---|---|---|---|---|
| Ana | ana@mail.test | Dune | Herbert | 2026-10-01 |
| Ana | ana@mail.test | Emma | Austen | 2026-10-03 |
| Ben | ben@mail.test | Dune | Herbert | 2026-10-05 |
| Ben | ben@mail.test | Persuasion | Austen | 2026-10-06 |
| Cy | cy@mail.test | Emma | Austen | 2026-10-07 |
| Cy | cy@mail.test | Ulysses | Joyce | 2026-10-09 |
Complete the loans table with the key you chose: member, book and date together.
CREATE TABLE loans ( member_id INTEGER NOT NULL REFERENCES members(id), book_id INTEGER NOT NULL REFERENCES books(id), borrowed TEXT NOT NULL, ________________ -- ← the key of a loan);Check the library's split
Here is one way to finish the job. The library is split into four tables with number keys: members (3 rows, with email UNIQUE), authors (3), books (4, each with an author_id) and loans (6, keyed by member, book and date). Joining them back gives the 6 rows of loans_flat, the same rows as the table in the steps above:
And the UNIQUE on email refuses a new member who gives Ana's email:
- Find the repeated facts in a library's loans, name the key of a loan, choose UNIQUE for emails, move the author by the second rule, and write a three-column key.