-
Notifications
You must be signed in to change notification settings - Fork 2
/
structure.sql
46 lines (42 loc) · 1.22 KB
/
structure.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 client(
id SERIAL PRIMARY KEY NOT NULL,
first_name TEXT NOT NULL,
last_name TEXT NOT NULL,
passport_number CHAR(9) NOT NULL
);
CREATE TABLE guide(
id SERIAL PRIMARY KEY NOT NULL,
first_name TEXT NOT NULL,
last_name TEXT NOT NULL
);
CREATE TABLE destination(
id SERIAL PRIMARY KEY NOT NULL,
country TEXT NOT NULL,
city TEXT NOT NULL
);
CREATE TABLE trip(
id SERIAL PRIMARY KEY NOT NULL,
destination_id INT NOT NULL,
departure_date DATE NOT NULL,
return_date DATE NOT NULL,
suggested_price INT NOT NULL,
guide_id INT NOT NULL,
CONSTRAINT fk_destination
FOREIGN KEY(destination_id)
REFERENCES destination(id),
CONSTRAINT fk_guide
FOREIGN KEY(guide_id)
REFERENCES guide(id)
);
CREATE TABLE booking(
id SERIAL PRIMARY KEY NOT NULL,
trip_id INT NOT NULL,
client_id INT NOT NULL,
negotiated_price INT NOT NULL,
CONSTRAINT fk_trip
FOREIGN KEY(trip_id)
REFERENCES trip(id),
CONSTRAINT fk_client
FOREIGN KEY(client_id)
REFERENCES client(id)
);