-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.sql
120 lines (106 loc) · 2.74 KB
/
init.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
drop table if exists nation cascade;
drop table if exists relation_diplo cascade;
drop table if exists navires cascade;
drop table if exists ports cascade;
drop table if exists voyage cascade;
drop table if exists produits cascade;
drop table if exists cargaison cascade;
drop table if exists "etape transitoire" cascade;
create table nation
(
nom char(20),
id_nation serial
constraint nation_pk
primary key
);
create table relation_diplo
(
nation_id1 integer
constraint n1
references nation,
nation_id2 integer
constraint n2
references nation,
relation varchar(50),
debut date
);
create table navires
(
id_navire serial
constraint navires_pk
primary key,
categorie varchar(20),
typet integer,
volume integer,
distancemax integer,
passagermax integer,
nation_id integer
constraint navires_nation_id_nation_fk
references nation
);
create table ports
(
id_port serial
constraint ports_pk
primary key,
nom varchar(50),
localisation varchar(50),
taille integer,
typet integer,
nation_id integer not null
constraint nid
references nation
);
create table voyage
(
id_voyage serial
constraint voyage_pk
primary key,
id_provenance integer
constraint port_provenance
references ports,
id_destination integer
constraint port_destination
references ports,
distance integer,
navire_id integer
constraint voyage_navires_id_navire_fk
references navires,
intercontinental boolean,
debut date,
fin date,
voyageur integer,
constraint intercontiental
check (((intercontinental = true) AND (distance >= 1000)) OR (intercontinental <> true))
);
create table produits
(
id serial
constraint produits_pk
primary key,
nom varchar(50),
perisable boolean not null,
prix integer,
poids integer
);
create table cargaison
(
id_cargaison integer not null,
produit_id integer not null,
quantité integer,
voyage_id integer
constraint cargaison_voyage_id_voyage_fk
references voyage,
etape integer
);
create table "etape transitoire"
(
port_id integer
constraint "etape transitoire_ports_id_port_fk"
references ports,
voyage_id integer
constraint "etape transitoire_voyage_id_voyage_fk"
references voyage,
ordre integer,
changement_passager integer
);