We use cookies to enhance your experience on the site
CodeWorlds

Special drawers - DATE, BOOLEAN and ENUM

Beyond numbers and text, the Library needs a few drawers with a special purpose. Get to know them so your shelves describe the world precisely.

DATE and DATETIME - time in the Library

  • DATE - a date alone, e.g.
    2024-03-15
    . Ideal for
    data_wypozyczenia
    or
    data_zwrotu
    .
  • DATETIME - a date together with a time, e.g.
    2024-03-15 14:30:00
    . Use it when the exact moment matters, e.g.
    data_logowania
    .

Remember: if the day alone is enough - DATE. If you also need the clock - DATETIME.

BOOLEAN - true or false

  • BOOLEAN (in MySQL it is really TINYINT) - stores a true/false value. Great for fields like
    dostepna
    :
1dostepna BOOLEAN DEFAULT TRUE

In MySQL

TRUE
is 1 and
FALSE
is 0 - but you can write it in human terms.

ENUM - a list of allowed values

  • ENUM('a','b','c') - the column may take only one of a predefined list of values. Great for states with a fixed set of options:
1stan ENUM('nowy', 'uzywany', 'zniszczony')

A copy can only be new, used or destroyed - MySQL will accept nothing else. It is a guard that lets no random values in.

Example: the egzemplarze shelf

1CREATE TABLE egzemplarze (
2  id INT AUTO_INCREMENT PRIMARY KEY,
3  data_zakupu DATE,
4  dostepna BOOLEAN DEFAULT TRUE,
5  stan ENUM('nowy', 'uzywany', 'zniszczony')
6);

The purchase date, availability and state - each drawer matched to its content.

Go to CodeWorlds