-
Notifications
You must be signed in to change notification settings - Fork 0
/
project.sql
268 lines (192 loc) · 7.22 KB
/
project.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
drop table member_companies;
drop table isMember;
drop table from_to;
drop table has_premium_lounge_in;
drop table on_board;
drop table airliner_oo1;
drop table airliner_oo2;
drop table air_alliances;
drop table airline_companies;
drop table airports;
drop table passengers;
create table air_alliances
(aa_name varchar(20) not null,
primary key (aa_name));
grant select on air_alliances to public;
create table airports
(airport_code char(3) not null,
primary key (airport_code));
grant select on airports to public;
create table passengers
(passport# int not null,
pname varchar(20),
primary key (passport#));
grant select on passengers to public;
create table airline_companies
(ac_name varchar(20) not null,
location varchar(20),
primary key (ac_name));
grant select on airline_companies to public;
create table member_companies
(aa_name varchar(20) not null,
ac_name varchar(20) not null,
primary key (aa_name, ac_name),
foreign key (aa_name) references air_alliances,
foreign key (ac_name) references airline_companies);
grant select on member_companies to public;
create table airliner_oo1
(flight# char(6),
ac_name varchar(20) not null,
from_airport_code char(3) not null,
to_airport_code char(3) not null,
model# varchar(15),
primary key (flight#),
foreign key (ac_name) references airline_companies ON DELETE CASCADE,
foreign key (to_airport_code) references airports ON DELETE CASCADE,
foreign key (from_airport_code) references airports ON DELETE CASCADE);
grant select on airliner_oo1 to public;
create table airliner_oo2
(flight# char(6) not null,
departure_time date not null,
arrival_time date not null,
primary key (flight#, departure_time),
unique (flight#, arrival_time));
grant select on airliner_oo2 to public;
create table isMember
(aa_name varchar(20) not null,
passport# int not null,
primary key (aa_name, passport#),
foreign key (aa_name) references air_alliances ON DELETE CASCADE,
foreign key (passport#) references passengers ON DELETE CASCADE);
grant select on isMember to public;
create table from_to
(from_airport_code char(3) not null,
to_airport_code char(3) not null,
primary key (from_airport_code, to_airport_code),
foreign key (from_airport_code) references airports ON DELETE CASCADE,
foreign key (to_airport_code) references airports ON DELETE CASCADE);
grant select on from_to to public;
create table has_premium_lounge_in
(airport_code char(3) not null,
aa_name varchar(20) not null,
primary key (airport_code, aa_name),
foreign key (airport_code) references airports ON DELETE CASCADE,
foreign key (aa_name) references air_alliances ON DELETE CASCADE);
grant select on has_premium_lounge_in to public;
create table on_board
(passport# int not null,
flight# char(6) not null,
departure_time date not null,
destination char(3),
primary key (passport#, departure_time),
foreign key (passport#) references passengers ON DELETE CASCADE,
foreign key (flight#, departure_time) references airliner_oo2 ON DELETE CASCADE,
foreign key (flight#) references airliner_oo1 ON DELETE CASCADE,
foreign key (destination) references airports ON DELETE CASCADE);
grant select on on_board to public;
insert into airline_companies
values('Air Canada', 'Dorval');
insert into airline_companies
values('Air China', 'Beijing');
insert into airline_companies
values('Korean Air', 'Seoul');
insert into airline_companies
values('Air France', 'Paris');
insert into airline_companies
values('Air India', 'Bombay');
insert into air_alliances
values('Star Alliance');
insert into air_alliances
values('SkyTeam');
insert into air_alliances
values('OneWorld');
insert into member_companies
values('Star Alliance', 'Air Canada');
insert into member_companies
values('Star Alliance', 'Air China');
insert into member_companies
values('Star Alliance', 'Air India');
insert into member_companies
values('SkyTeam', 'Korean Air');
insert into member_companies
values('SkyTeam', 'Air France');
insert into airports
values('PVG');
insert into airports
values('YVR');
insert into airports
values('BOM');
insert into airports
values('PEK');
insert into airports
values('ICN');
insert into airliner_oo1
values('AC025', 'Air Canada', 'PVG', 'YVR', 'Boeing 767');
insert into airliner_oo1
values('AC026', 'Air Canada', 'YVR', 'PVG', 'Boeing 767');
insert into airliner_oo1
values('KE071', 'Korean Air', 'ICN', 'YVR', 'Airbus A320');
insert into airliner_oo1
values('AI191', 'Air India', 'YVR', 'BOM', 'Boeing 787');
insert into airliner_oo1
values('CA7452', 'Air China', 'YVR', 'PEK', 'Airbus A320');
insert into airliner_oo2
values('AC025', TO_DATE('2016/03/27 11:02:44', 'yyyy/mm/dd hh24:mi:ss'), TO_DATE('2016/03/28 8:02:44', 'yyyy/mm/dd hh24:mi:ss'));
insert into airliner_oo2
values('AC026', TO_DATE('2016/03/27 13:02:44', 'yyyy/mm/dd hh24:mi:ss'), TO_DATE('2016/03/28 21:02:44', 'yyyy/mm/dd hh24:mi:ss'));
insert into airliner_oo2
values('KE071', TO_DATE('2016/03/27 2:02:44', 'yyyy/mm/dd hh24:mi:ss'), TO_DATE('2016/03/28 9:02:44', 'yyyy/mm/dd hh24:mi:ss'));
insert into airliner_oo2
values('AI191', TO_DATE('2016/03/27 11:02:44', 'yyyy/mm/dd hh24:mi:ss'), TO_DATE('2016/03/27 13:04:44', 'yyyy/mm/dd hh24:mi:ss'));
insert into airliner_oo2
values('CA7452', TO_DATE('2016/03/27 18:22:44', 'yyyy/mm/dd hh24:mi:ss'), TO_DATE('2016/03/28 17:02:44', 'yyyy/mm/dd hh24:mi:ss'));
insert into passengers
values(849373939, 'Morgot Anastazja');
insert into passengers
values(935485836, 'Franka Constance');
insert into passengers
values(936769603, 'Cleon Kyler');
insert into passengers
values(749648504, 'Darius Butrus');
insert into passengers
values(950474950, 'Kallisto Teofila');
insert into isMember
values('Star Alliance', 935485836);
insert into isMember
values('SkyTeam', 935485836);
insert into isMember
values('OneWorld', 936769603);
insert into isMember
values('Star Alliance', 749648504);
insert into isMember
values('SkyTeam', 849373939);
insert into from_to
values('PVG', 'YVR');
insert into from_to
values('YVR', 'PVG');
insert into from_to
values('ICN', 'YVR');
insert into from_to
values('YVR', 'BOM');
insert into from_to
values('YVR', 'PEK');
insert into has_premium_lounge_in
values('PVG', 'Star Alliance');
insert into has_premium_lounge_in
values('YVR', 'Star Alliance');
insert into has_premium_lounge_in
values('BOM', 'SkyTeam');
insert into has_premium_lounge_in
values('PEK', 'OneWorld');
insert into has_premium_lounge_in
values('PEK', 'Star Alliance');
insert into on_board
values(849373939, 'AC025', TO_DATE('2016/03/27 11:02:44', 'yyyy/mm/dd hh24:mi:ss'), 'YVR');
insert into on_board
values(935485836, 'AC026', TO_DATE('2016/03/27 13:02:44', 'yyyy/mm/dd hh24:mi:ss'), 'PVG');
insert into on_board
values(936769603, 'KE071', TO_DATE('2016/03/27 2:02:44', 'yyyy/mm/dd hh24:mi:ss'), 'YVR');
insert into on_board
values(749648504, 'AI191', TO_DATE('2016/03/27 11:02:44', 'yyyy/mm/dd hh24:mi:ss'), 'BOM');
insert into on_board
values(950474950, 'AI191', TO_DATE('2016/03/27 11:02:44', 'yyyy/mm/dd hh24:mi:ss'), 'BOM');