-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.sql
More file actions
33 lines (29 loc) · 929 Bytes
/
schema.sql
File metadata and controls
33 lines (29 loc) · 929 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
-- Schema for Comic Book Rental System
CREATE DATABASE IF NOT EXISTS comic_rental;
USE comic_rental;
-- Comics table
CREATE TABLE IF NOT EXISTS comics (
id INT AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(255) NOT NULL,
volume_count INT DEFAULT 0,
author VARCHAR(255) NOT NULL,
is_rented BOOLEAN DEFAULT FALSE
);
-- Members table
CREATE TABLE IF NOT EXISTS members (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
phone_number VARCHAR(50),
join_date DATE DEFAULT CURRENT_DATE
);
-- Rentals table
CREATE TABLE IF NOT EXISTS rentals (
id INT AUTO_INCREMENT PRIMARY KEY,
comic_id INT NOT NULL,
member_id INT NOT NULL,
rented_at DATETIME DEFAULT CURRENT_TIMESTAMP,
returned_at DATETIME NULL,
status ENUM('RENTED','RETURNED') NOT NULL DEFAULT 'RENTED',
FOREIGN KEY (comic_id) REFERENCES comics(id),
FOREIGN KEY (member_id) REFERENCES members(id)
);