· 8 years ago · Feb 12, 2018, 04:16 PM
1drop database if exists volare;
2create database volare;
3use volare;
4
5create table aeroporto(
6
7 idAeroporto int primary key auto_increment,
8 citta varchar (30) not null,
9 nazione varchar (3) not null,
10 numPiste int (2)
11
12);
13
14create table aereo(
15
16 idAereo int primary key auto_increment,
17 tipo varchar(30) not null,
18 numPasseggeri int(4) not null,
19 qtaMerci int (10)
20
21
22);
23
24create table voli (
25
26 idVolo varchar (6) primary key ,
27 giornoSett char (3) not null,
28 aeroportoPart int,
29 aeroportoArr int,
30 oraPart char (5) not null,
31 oraArr char (5) not null,
32 codAereo int ,
33 foreign key (codAereo) references aereo(idAereo) on delete cascade
34 on update cascade,
35
36 foreign key (aeroportoArr) references aeroporto(idAeroporto) on delete cascade
37 on update cascade,
38
39 foreign key (aeroportoPart) references aeroporto(idAeroporto) on delete cascade
40 on update cascade
41
42);
43
44insert into aeroporto (citta,nazione,numPiste) values
45( ' Torino ' , ' IT ' , null ) ,
46( ' Miami ' , ' US ' , 5 ) ,
47( ' Bologna ' , ' IT ' , 6 ) ,
48( ' Roma ' , ' IT ' , 7 ) ,
49( ' Praga ' , ' CZ ' , 8 ) ,
50( ' Napoli ' , ' IT ' , 9 ) ,
51( ' Parigi ' , ' FR ' , 10 ) ,
52( ' Venezia ' , ' IT ' , 11 ) ,
53( ' Lisbona ' , ' PT ' , 12 ) ;
54
55insert into aereo (tipo,numPasseggeri,qtaMerci) values
56( ' Transcontinentale ' , 200 , 30 ),
57( ' Cargo ' , 50 , 500 ),
58( ' Turistico ' , 30 , 5 ),
59( ' Privato ' , 20 , 2 );
60
61insert into voli (idVolo,giornoSett,aeroportoPart,aeroportoArr,oraPart,oraArr,codAereo) values
62( 'UA225' , ' Giovedi ' , 4 , 7 , ' 07:24 ' , ' 08:50 ' , 3 ) ,
63( 'BQ994' , ' Domenica ' , 3 , 4 , ' 13:59 ' , ' 15:20 ' , 4 ) ,
64( 'CZ942' , ' Lunedi ' , 5 , 2 , ' 17:20 ' , ' 23:50 ' , 1 ) ,
65( 'LF221' , ' Mercoledi ' , 1 , 4 , ' 23:40 ' , ' 04:22 ' , 2 ) ,
66( 'TF751' , ' Sabato ' , 8 , 6 , ' 02:22 ' , ' 16:43 ' , 1 ) ,
67( 'AZ274 ' , ' Lunedi ' , 2 , 1 , ' 05:23 ' , ' 07:22 ' , 3 ) ,
68( 'AZ221' , ' Domenica ' , 9 , 6 , ' 11:30 ' , ' 21:40 ' , 1 ) ;
69
70
71/*Le nazioni da cui parte e arriva il volo con codice AZ221; */
72
73select idVolo,nazione as NazionePartenza
74from voli,aeroporto
75where aeroportoPart =idAeroporto and idVolo = 'AZ221';