-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmysql6.sql
158 lines (143 loc) · 5.74 KB
/
mysql6.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
----------------------------------------------------------------------------------------------
#Table - Train containing Train details
-----------------------------------------------------------------------------------------------
create table Train
(
train_id int not null,
train_name varchar(50) not null,
train_type varchar(50) not null,
orignating_station varchar(50),
destination_station varchar(50),
primary key(train_id)
);
----------------------------------------------------------------------------------------------
#Table - Station containing station details
----------------------------------------------------------------------------------------------
create table station
(
station_id int not null,
station_name varchar(50),
primary key(station_id)
);
----------------------------------------------------------------------------------------------
#Table - Route containing route details
----------------------------------------------------------------------------------------------
create table route
(
train_id int not null,
stop_id int not null,
station_id varchar(10) not null,
arrival_time time not null,
depart_time time not null,
source_distance int not null,
primary key (train_id,stop_id),
foreign key (train_id) references train(train_id) on update cascade on delete cascade
);
-----------------------------------------------------------------------------------------------
#Table - Train_Class_type containing class types and fare associated with each class types
-----------------------------------------------------------------------------------------------
create table train_class_type
(
train_id int not null,
class_type1 varchar(10) not null,
fare_type1 float not null,
class_type2 varchar(10) not null,
fare_type2 float not null,
class_type3 varchar(10) not null,
fare_type3 float not null,
primary key (train_id)
);
set foreign_key_checks=0;
--------------------------------------------------------------------------------------------------
#Table - Train_Schedule containing details of schedule of each train
--------------------------------------------------------------------------------------------------
create table train_schedule
(
train_id int not null,
train_name varchar(50) not null,
days_running_on varchar(10) not null,
start_time time not null,
primary key (train_id)
);
--------------------------------------------------------------------------------------------------
#Table - Passenger containing details of passengers booking the tickets
--------------------------------------------------------------------------------------------------
create table Passenger
(
full_name varchar(50) not null,
mobile_number int not null,
email_id varchar(50) not null,
Address varchar(50) not null,
city varchar(50) not null,
state varchar(50) not null,
Gender varchar(10) not null,
dob date not null,
check(GENDER in ('Male', 'Female', 'Unknown')),
primary key (email_id)
);
--------------------------------------------------------------------------------------------------
#Table - Train_booking_status containing details of train booking status
--------------------------------------------------------------------------------------------------
create table train_booking_status
(
train_id int not null,
available_date varchar(20) not null,
seat_booked_status int,
waiting_seat_status int,
available_seat_status int,
primary key (train_id,available_date),
foreign key (train_id) references train(train_id) on update cascade on delete cascade
);
--------------------------------------------------------------------------------------------------
#Table - reservation_status containing details of schedule of each train
--------------------------------------------------------------------------------------------------
create table reservation_status
(
train_id int not null,
available_date varchar(20) not null,
email_id varchar(30) not null,
PNR varchar(20) not null,
reservation_date date not null,
reservation_status varchar(10),
foreign key (train_id,available_date) references train_booking_status(train_id,available_date) on update cascade on delete cascade,
foreign key (email_id) references passenger(email_id) on update cascade on delete cascade,
primary key (train_id,available_date,email_id,PNR)
);
--------------------------------------------------------------------------------------------------
#Table - ticket contains details of schedule on a ticket
--------------------------------------------------------------------------------------------------
create table ticket
(
PNR varchar(20) not null,
source_station_name varchar(20) not null,
destination_station_name varchar(20) not null,
ticket_status varchar(10) not null,
train_id int not null,
foreign key (train_id) references Train (train_id) on update cascade on delete cascade,
primary key (PNR)
);
--------------------------------------------------------------------------------------------------
#Table - passenger_track_using_pnr contains details for each booking made
--------------------------------------------------------------------------------------------------
create table passenger_track_using_PNR
(
PNR varchar(20) not null,
seat_number int not null,
coach_number varchar(5) not null,
Passenger_name varchar(20) not null,
Gender varchar(10) not null,
train_id int not null,
foreign key (train_id) references train(train_id) on update cascade on delete cascade,
primary key(PNR, seat_number)
);
--------------------------------------------------------------------------------------------------
#Table - station_on_route contains details of stations present on a particular route
--------------------------------------------------------------------------------------------------
create table station_on_route
(
train_id int not null,
station_id varchar(20) not null,
stop_number int not null,
primary key (Train_id, station_id)
);
select now()