We use cookies to enhance your experience on the site
CodeWorlds

The Great Work of the scriptorium - the biblioteka shelf project

The time has come to design a full-fledged shelf on your own, combining everything you have learned in the scriptorium. We will build the heart of the lending desk - the wypozyczenia (loans) table, which links books with readers.

What does the wypozyczenia shelf need?

Each loan is one row. We must record:

  • id - the primary key, numbered automatically,
  • ksiazka_id - which book was borrowed (a required field),
  • czytelnik_id - who borrowed it (a required field),
  • data_wypozyczenia - when (a required field),
  • data_zwrotu - when it was returned (may be empty if the book is still with the reader).

Assembling the project step by step

  1. Primary key - we start with
    id INT AUTO_INCREMENT PRIMARY KEY
    . It is a pattern you already know.
  2. Required fields -
    ksiazka_id
    ,
    czytelnik_id
    and
    data_wypozyczenia
    must always have a value, so we add NOT NULL.
  3. Optional field - we leave
    data_zwrotu
    without NOT NULL, because while the book is on loan it stays empty (NULL).

The finished pattern

1CREATE TABLE wypozyczenia (
2  id INT AUTO_INCREMENT PRIMARY KEY,
3  ksiazka_id INT NOT NULL,
4  czytelnik_id INT NOT NULL,
5  data_wypozyczenia DATE NOT NULL,
6  data_zwrotu DATE
7);

Why is this a good design?

  • Each row has a unique identifier thanks to the primary key.
  • The required fields protect against incomplete records (a loan without a book makes no sense).
  • The optional field (
    data_zwrotu
    ) faithfully reflects reality - until the return happens, it stays empty.

Build this shelf and you will have the foundation of the entire lending desk. This is your Great Work of the scriptorium!

Go to CodeWorlds