-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDDL Queries.sql
165 lines (150 loc) · 6.65 KB
/
DDL Queries.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
CREATE DATABASE IF NOT EXISTS `airportdb`;
USE airportdb;
CREATE TABLE IF NOT EXISTS `airline` (
`airline_id` smallint NOT NULL AUTO_INCREMENT,
`iata` char(2) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
`airlinename` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`base_airport` int NOT NULL,
PRIMARY KEY (`airline_id`)
);
CREATE TABLE IF NOT EXISTS `airplane_type` (
`type_id` int NOT NULL AUTO_INCREMENT,
`identifier` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`description` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
PRIMARY KEY (`type_id`)
);
CREATE TABLE IF NOT EXISTS `airplane` (
`airplane_id` int NOT NULL AUTO_INCREMENT,
`capacity` mediumint unsigned NOT NULL,
`type_id` int NOT NULL,
`airline_id` int NOT NULL,
PRIMARY KEY (`airplane_id`)
);
CREATE TABLE IF NOT EXISTS `airport_geo` (
`airport_id` smallint NOT NULL,
`name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
`city` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`country` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`latitude` decimal(11,8) NOT NULL,
`longitude` decimal(11,8) NOT NULL,
`geolocation` TEXT NOT NULL,
PRIMARY KEY (`airport_id`)
);
CREATE TABLE IF NOT EXISTS `airport_reachable` (
`airport_id` smallint NOT NULL,
`hops` int DEFAULT NULL,
PRIMARY KEY (`airport_id`)
);
CREATE TABLE IF NOT EXISTS `airport` (
`airport_id` smallint NOT NULL AUTO_INCREMENT,
`iata` char(3) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`icao` char(4) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
`name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
PRIMARY KEY (`airport_id`)
);
CREATE TABLE IF NOT EXISTS `booking` (
`booking_id` int NOT NULL AUTO_INCREMENT,
`flight_id` int NOT NULL,
`seat` char(4) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`passenger_id` int NOT NULL,
`price` decimal(10,2) NOT NULL,
PRIMARY KEY (`booking_id`)
);
CREATE TABLE IF NOT EXISTS `employee` (
`employee_id` int NOT NULL AUTO_INCREMENT,
`firstname` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
`lastname` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
`birthdate` date NOT NULL,
`sex` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`street` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
`city` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
`zip` int NOT NULL,
`country` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
`emailaddress` varchar(120) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`telephoneno` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`salary` decimal(8,2) DEFAULT NULL,
`department` enum('Marketing','Buchhaltung','Management','Logistik','Flugfeld') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`username` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`password` char(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
PRIMARY KEY (`employee_id`)
);
CREATE TABLE IF NOT EXISTS `flight_log` (
`flight_log_id` int unsigned NOT NULL AUTO_INCREMENT,
`log_date` datetime NOT NULL,
`user` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
`flight_id` int NOT NULL,
`flightno_old` char(8) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
`flightno_new` char(8) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
`from_old` smallint NOT NULL,
`to_old` smallint NOT NULL,
`from_new` smallint NOT NULL,
`to_new` smallint NOT NULL,
`departure_old` datetime NOT NULL,
`arrival_old` datetime NOT NULL,
`departure_new` datetime NOT NULL,
`arrival_new` datetime NOT NULL,
`airplane_id_old` int NOT NULL,
`airplane_id_new` int NOT NULL,
`airline_id_old` smallint NOT NULL,
`airline_id_new` smallint NOT NULL,
`comment` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
PRIMARY KEY (`flight_log_id`)
);
CREATE TABLE IF NOT EXISTS `flight` (
`flight_id` int NOT NULL AUTO_INCREMENT,
`flightno` char(8) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
`from` smallint NOT NULL,
`to` smallint NOT NULL,
`departure` datetime NOT NULL,
`arrival` datetime NOT NULL,
`airline_id` smallint NOT NULL,
`airplane_id` int NOT NULL,
PRIMARY KEY (`flight_id`)
);
CREATE TABLE IF NOT EXISTS `flightschedule` (
`flightno` char(8) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
`from` int NOT NULL,
`to` int NOT NULL,
`departure` time NOT NULL,
`arrival` time NOT NULL,
`airline_id` int NOT NULL,
`monday` tinyint(1) DEFAULT '0',
`tuesday` tinyint(1) DEFAULT '0',
`wednesday` tinyint(1) DEFAULT '0',
`thursday` tinyint(1) DEFAULT '0',
`friday` tinyint(1) DEFAULT '0',
`saturday` tinyint(1) DEFAULT '0',
`sunday` tinyint(1) DEFAULT '0',
PRIMARY KEY (`flightno`)
);
CREATE TABLE IF NOT EXISTS `passenger` (
`passenger_id` int NOT NULL AUTO_INCREMENT,
`passportno` char(9) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
`firstname` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
`lastname` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
PRIMARY KEY (`passenger_id`)
);
CREATE TABLE IF NOT EXISTS `passengerdetails` (
`passenger_id` int NOT NULL,
`birthdate` date NOT NULL,
`sex` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`street` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
`city` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
`zip` smallint NOT NULL,
`country` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
`emailaddress` varchar(120) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`telephoneno` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
PRIMARY KEY (`passenger_id`)
);
CREATE TABLE IF NOT EXISTS `weatherdata` (
`log_date` date NOT NULL,
`time` time NOT NULL,
`station` int NOT NULL,
`temp` decimal(3,1) NOT NULL,
`humidity` decimal(4,1) NOT NULL,
`airpressure` decimal(10,2) NOT NULL,
`wind` decimal(5,2) NOT NULL,
`weather` enum('Nebel-Schneefall','Schneefall','Regen','Regen-Schneefall','Nebel-Regen','Nebel-Regen-Gewitter','Gewitter','Nebel','Regen-Gewitter') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`winddirection` smallint NOT NULL,
PRIMARY KEY (`log_date`,`time`,`station`)
);