Railway Managment System
Railway Managment System
Railway Managment System
PES University
UE18CS252
Submitted By
This project is about creating a database about the Railway Management System. The
railway management system facilitates the passengers to enquire about the trains
available on the basis of source and destination, booking and cancellation of tickets,
enquire about the status of the booked ticket, etc. The aim of case study is to design and
develop a database maintaining the records of different trains, stations, and passengers.
The record of the train includes its number, name, days on which it is available etc.
Passengers can book their tickets for the train in which seats are available. For this,
passengers have to provide the desired train number and the date for which ticket is to be
booked. Before booking a ticket for a passenger, the validity of train number and booking
date is checked. Once the train number and booking date are validated, it is checked
whether the seat is available. If yes, the ticket is booked with confirm status and
corresponding ticket No is generated which is stored along with other details of the
passenger. The ticket once booked can be cancelled at any time. For this, the passenger
has to provide the ticket ID (the unique key). The ticket ID is searched and the
corresponding record is deleted.
Introduction 2
Data Model 2
FD and Normalization 2
DDL 3
Triggers 3
SQL Queries 3
Conclusion 3
Introduction
Following are the entities in our miniworld along with their attributes.
`Account`
(
`Username` varchar(15) NOT NULL,
Contact
(
`Username` varchar(15) NOT NULL DEFAULT '',
Passenger
`Passenger_Id` int(11) NOT NULL AUTO_INCREMENT,
`Station`
(
`Station_Code` char(5) NOT NULL DEFAULT
'',
`Station_Name` varchar(25) NOT NULL,
Stoppage
`Train_No` int(6) NOT NULL DEFAULT '0',
Ticket
{ `Ticket_No` int(10) NOT NULL AUTO_INCREMENT,
Data Model
FD and Normalization
Functional dependencies
TRAIN
`Train_No`->( `Name`, `Seat_Sleeper` , `Seat_First_Class_AC`, `Seat_Second_Class_AC`,
`Seat_Third_Class_AC`,`Wifi`,`Food`,`Run_On_Sunday``Run_On_Monday``Run_On_Tuesd
ay` `Run_On_Wednesday` `Run_On_Thursday` `Run_On_Friday`,`Run_On_Saturday` )
STOPPAGE
TICKET
STATION
PASSENGER
`Passenger_Id`-> (`First_Name` `Last_Name` `Gender` `Phone_No` `Ticket_No` `Age`
`Class`)
ACCOUNT
-No non-prime attribute is dependent on the proper subset of any candidate key of
table.
DDL
CREATE DATABASE PROJECT;
USE PROJECT;
alter table Stoppage ADD CHECK (EXTRACT(HOUR FROM Arrival_Time) <24 AND
EXTRACT(HOUR FROM Departure_Time) <24);
Triggers
A trigger has been created which is invoked each time a ticket is cancelled.The trigger helps
in increasing the number of seats in a coach after cancellation.
delimiter //
create trigger cancellation
before delete on ticket
for each row
BEGIN
set @trainno=old.train_no;
set @ticketno=old.ticket_no;
SET @class = (SELECT p.class
FROM PASSENGER p
WHERE p.ticket_no = @ticketno);
if @class='first class ac' then
UPDATE Train set Seat_First_Class_AC = Seat_First_Class_AC+1 WHERE Train_No =
@trainno ;
elseif @class='sleeper' then
UPDATE Train set Seat_Sleeper = Seat_Sleeper+1 WHERE Train_No = @trainno ;
elseif @class='second class ac' then
UPDATE Train set Seat_Second_Class_AC = Seat_Second_Class_AC+1 WHERE
Train_No = @trainno ;
elseif @class='third class ac' then
UPDATE Train set Third_Class_AC = Seat_Third_Class_AC+1 WHERE Train_No =
@trainno ;
end if;
END//
delimiter ;
SQL Queries
/* Find total number of first class seats available on any train that reaches bangalore
before 7pm on Monday .*/
create view a(Station_code,Train_no,Arrival_Time)as
SELECT Stoppage.Station_code,Train_no,Arrival_Time
from Station inner join Stoppage on station.Station_code=Stoppage.Station_code where
station.Station_name='BANGALORE';
select * from a;
select * from b;
select *from c;
SELECT SUM(First_class_seats)
FROM c;
/* Find the time at which last train leaves New delhi station */
Select Phone_no from Contact where username IN (Select Username from account where
Email_id='ajitesh@pes.edu');