-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbooks.sql
46 lines (39 loc) · 929 Bytes
/
books.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
CREATE TABLE books (
id INTEGER PRIMARY KEY,
title VARCHAR(255) NOT NULL,
author_id INTEGER,
FOREIGN KEY(author_id) REFERENCES author(id)
);
CREATE TABLE authors (
id INTEGER PRIMARY KEY,
name VARCHAR(255) NOT NULL,
primary_language_id INTEGER,
FOREIGN KEY(primary_language_id) REFERENCES primary_language(id)
);
CREATE TABLE primary_languages (
id INTEGER PRIMARY KEY,
name VARCHAR(255) NOT NULL
);
INSERT INTO
primary_languages (id, name)
VALUES
(1, "English"),
(2, "German"),
(3, "French"),
(4, "Spanish");
INSERT INTO
authors (id, name, primary_language_id)
VALUES
(1, "J.R.R. Tolkien", 1),
(2, "Franz Kafka", 2),
(3, "Voltaire", 3),
(4, "Miguel de Cervantes", 4),
(5, "Unpublished Author", NULL);
INSERT INTO
books (id, title, author_id)
VALUES
(1, "The Hobbit", 1),
(2, "Metamorphosis", 2),
(3, "Candide", 3),
(4, "Don Quixote", 4),
(5, "Unclaimed Book", NULL);