-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdesign.sql
More file actions
29 lines (24 loc) · 815 Bytes
/
Copy pathdesign.sql
File metadata and controls
29 lines (24 loc) · 815 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
CREATE TABLE continents(
id BIGSERIAL PRIMARY KEY,
name VARCHAR(15) NOT NULL UNIQUE
);
CREATE TABLE countries(
id BIGSERIAL PRIMARY KEY,
name VARCHAR(50) NOT NULL UNIQUE,
surface REAL NOT NULL,
population INTEGER NOT NULL,
continent_id BIGSERIAL NOT NULL,
CONSTRAINT fk_countries_continents FOREIGN KEY (continent_id) REFERENCES continents(id)
);
CREATE TABLE people(
id BIGSERIAL PRIMARY KEY,
first_name VARCHAR(50) NOT NULL,
last_name VARCHAR(50) NOT NULL
);
CREATE TABLE citizenships(
id BIGSERIAL PRIMARY KEY,
country_id BIGSERIAL NOT NULL,
person_id BIGSERIAL NOT NULL,
CONSTRAINT fk_citizenships_countries FOREIGN KEY (country_id) REFERENCES countries(id),
CONSTRAINT fk_citizenships_people FOREIGN KEY (person_id) REFERENCES people(id)
);