-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmidproject.sql
147 lines (120 loc) · 3.64 KB
/
midproject.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
/*
need to add a trigger to customer because customer_type is changing dynamically
added new table customer_type with the relevant discount for customer_types
added a price attribute to booking because price changes with the customer_type
need to add a price function to calculate price for a booking
rethink about seat table
rethink about flight table......no need of it
*/
create database Airplane;
use Airplane;
CREATE TABLE customer (
user_id int(5) auto_increment,
name varchar(20),
email varchar(20),
password varchar(20),
age int(2),
customer_type enum('Guest','Frequent','Gold') NOT NULL,
mobile_no varchar(20),
PRIMARY KEY (user_id)
);
CREATE TABLE aircraft (
craft_id int(5) auto_increment,
craft_type varchar(20),
seats int(3),
PRIMARY KEY (craft_id)
);
CREATE TABLE admins (
admin_id int(2) auto_increment,
name varchar(20),
email varchar(20),
password varchar(20),
PRIMARY KEY (admin_id)
);
CREATE TABLE location (
location_id int(5) auto_increment,
location varchar(20),
locateTo int(5),
PRIMARY KEY (location_id),
FOREIGN KEY (locateTo) references location(location_id)
);
CREATE TABLE airport (
airport_code int(5) auto_increment,
location_id int(5),
airport_name VARCHAR(50) not null,
PRIMARY KEY (airport_code),
FOREIGN KEY (location_id) references location(location_id)
);
CREATE TABLE route (
route_id int(5) auto_increment,
origin int(5),
destination int(5),
PRIMARY KEY (route_id),
FOREIGN KEY (origin) references airport(airport_code),
FOREIGN KEY (destination) references airport(airport_code)
);
CREATE TABLE flight (
flight_id int(5) auto_increment,
route_id int(5),
PRIMARY KEY (flight_id),
FOREIGN KEY (route_id) references route(route_id)
);
CREATE TABLE predefined_schedule (
schedule_id int(5) auto_increment,
craft_id int(5),
flight_id int(5),
day varchar(20),
departure_time varchar(20),
arrival_time varchar(20),
PRIMARY KEY (schedule_id),
FOREIGN KEY (craft_id) references aircraft(craft_id),
FOREIGN KEY (flight_id) references flight(flight_id)
);
CREATE TABLE class (
class_id int(5) auto_increment,
route_id int(5),
price varchar(20),
class varchar(20),
PRIMARY KEY (class_id),
FOREIGN KEY (route_id) references route(route_id)
);
CREATE TABLE seat (
seat_id int(5) auto_increment,
craft_id int(5),
seat_no varchar(20),
PRIMARY KEY (seat_id),
FOREIGN KEY (craft_id) references aircraft(craft_id)
);
CREATE TABLE booking (
booking_id int(5) auto_increment,
user_id int(5) not null,
schedule_id int(5) not null,
class_id int(5) not null,
seat_id int(5) not null,
booking_date varchar(20) not null,
booked_date varchar(20) not null,
price varchar(20),
PRIMARY KEY (booking_id),
FOREIGN KEY (schedule_id) references predefined_schedule(schedule_id),
FOREIGN KEY (seat_id) references seat(seat_id),
FOREIGN KEY (user_id) references customer(user_id),
FOREIGN KEY (class_id) references class(class_id)
);
CREATE TABLE real_schedule (
real_schedule_id int(5) auto_increment,
flight_id int(5),
schedule_id int(5),
starting_time varchar(20),
arrival_time varchar(20),
craft_id int(5),
PRIMARY KEY (real_schedule_id),
FOREIGN KEY (flight_id) references flight(flight_id),
FOREIGN KEY (schedule_id) references predefined_schedule(schedule_id),
FOREIGN KEY (craft_id) references aircraft(craft_id)
);
CREATE TABLE customer_state (
customer_state varchar(10) not null,
discount int(2) not null,
bookings_needed int(2) not null,
PRIMARY KEY (customer_state)
);