-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschema.sql
52 lines (42 loc) · 1.19 KB
/
schema.sql
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
DROP DATABASE IF EXISTS catalog_of_my_things;
DROP TABLE IF EXISTS Music_album, Game, Book, Item, Label, Genre, Author;
CREATE DATABASE catalog_of_my_things;
CREATE TABLE Author (
id INT PRIMARY KEY AUTO_INCREMENT,
first_name VARCHAR(255) NOT NULL,
last_name VARCHAR(255) NOT NULL
);
CREATE TABLE Genre (
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(255) NOT NULL
);
CREATE TABLE Label (
id INT PRIMARY KEY AUTO_INCREMENT,
title VARCHAR(255) NOT NULL,
color VARCHAR(20)
);
CREATE TABLE Item (
id INT PRIMARY KEY AUTO_INCREMENT,
label_id INT NOT NULL,
publish_date DATE NOT NULL,
archived BOOLEAN NOT NULL,
FOREIGN KEY (label_id) REFERENCES Label(id)
);
CREATE TABLE Music_album (
id INT PRIMARY KEY AUTO_INCREMENT,
on_spotify BOOLEAN NOT NULL,
item_id INT NOT NULL,
FOREIGN KEY (item_id) REFERENCES Item(id)
);
CREATE TABLE Book (
item_id INT PRIMARY KEY,
publisher VARCHAR(255) NOT NULL,
cover_state VARCHAR(50),
FOREIGN KEY (item_id) REFERENCES Item(id)
);
CREATE TABLE Game (
item_id INT PRIMARY KEY,
multiplayer BIT NOT NULL,
last_played_at DATE NOT NULL,
FOREIGN KEY (item_id) REFERENCES Item(id)
);