bubble_chart StackLab

Database Migration

19 steps · pending Not started · person_outline Guest
arrow_back Back

Create the books table

Next, we need somewhere to store our books. Add the following SQL below the students table:

code sql
CREATE TABLE IF NOT EXISTS books (
    book_id INT AUTO_INCREMENT PRIMARY KEY,

    book_title VARCHAR(50) NOT NULL,
    book_author VARCHAR(100) NOT NULL,
    book_category VARCHAR(50) NOT NULL,

    book_created_at TIMESTAMP NOT NULL
        DEFAULT CURRENT_TIMESTAMP

) ENGINE=InnoDB
  DEFAULT CHARSET=utf8mb4
  COLLATE=utf8mb4_general_ci;
The table contains:
code text
books
├── book_id
├── book_title
├── book_author
├── book_category
└── book_created_at
The important thing to notice is that both students and books have their own primary key. These IDs will later be used by the borrow table.

login Sign in to save your progress permanently. info Progress is saved in your browser session
format_list_numbered Step 6 of 19