-
Notifications
You must be signed in to change notification settings - Fork 0
/
import_db.sql
43 lines (38 loc) · 869 Bytes
/
import_db.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
DROP TABLE IF EXISTS paintings;
DROP TABLE IF EXISTS painters;
CREATE TABLE paintings
(
id INTEGER PRIMARY KEY,
title VARCHAR(255) NOT NULL,
year INTEGER,
painter_id INTEGER NOT NULL,
FOREIGN KEY (painter_id) REFERENCES painters(id)
);
CREATE TABLE painters
(
id INTEGER PRIMARY KEY,
name VARCHAR(255) NOT NULL,
birth_year INTEGER
);
INSERT INTO
painters
(name, birth_year)
VALUES
('Claude Monet', 1840),
('Edvard Munch', 1863);
INSERT INTO
paintings
(title, year, painter_id)
VALUES
('Wisteria', 1925, (SELECT id
FROM painters
WHERE name = 'Claude Monet')),
('The Scream', 1893, (SELECT id
FROM painters
WHERE name = 'Edvard Munch')),
('The Yellow Log', 1912, (SELECT id
FROM painters
WHERE name = 'Edvard Munch')),
('The Haymaker', 1917, (SELECT id
FROM painters
WHERE name = 'Edvard Munch'));