Railway Management System
Railway Management System
PROJECT REPORT
By
1|Page
INDEX
Abstract……………………………………………………………………3
Introduction…………………………………………………….……….…4
Project Description…………………………………………………………5
ER Diagram…………………………………………………………………8
Schema Diagram………………………..………………………………..…9
Creating Commands………………………………………………………..10
Abstract
2|Page
The Railway Reservation 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, train status, and passengers.
In our country India, there are number of counters for the reservation el the
seats and one can easily make reservations and get tickets. Then this projest
contains entity relationship model diagram based on railway reservation system
and introduction to relation model.
Introduction
3|Page
Database is an organized collection of data. The data is typically organized to
model aspects of reality in a way that supports processes requiring information.
A DBMS makes it possible for end-users to create, read, update and delete data
in a database. The DBMS essentially serves as an interface between the database
and end-users or application programs, ensuring that data is consistently
organized and remains easily accessible. The DBMS manages three important
things: the data, the database engine that allows data to be accessed. locked and
modified and the database schema, which defines the database's logical structure.
These three foundational elements help provide concurrency, security, data
integrity, and uniform administration procedures. The DBMS can offer both
logical and physical data independence Which means it can protect users and
applications from needing to know where data is stored or having to be concerned
about changes to the physical structure of data.
Project Description
4|Page
This Project is about creating the database about Railway Reservation System
The railway reservation system facilitates the passengers to enquire about the
trains available on the basis of 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, train
status, and users. The record of train includes its number, name,
description,capacity,time, destination.
Users can book their tickets for the train in which seats are available. For this,
user has to provide the desired train number and the date for which ticket is to be
booked. Before booking a ticket for a user, the validity of train number is checked.
Once the train number and time are validated, it is checked whether the seat is
available. If yes, the ticket is booked with confirm status and corresponding ticket
ID is generated which is stored along with other details of the user. The ticket
once booked can be cancelled at any time. For this, the passenger has to provide
the ticket ID (the unique Key).User can do the payment by different
modes(UPI,Cash,Card).
5|Page
ENTITIES ATTRIBUTES
User ID
First_Name
Middle_Name
Last _Name
Age
Gender
City
Pin_code
State
Mobile_no.
Train Train_No
Name
Capacity
Destination
Train_Desc
Arrival_Time
Station Station_No
Arrival_Time
Hault
Departure
Name
Train_No
Ticket Ticket_id
No. Of Passenger
First_Name
Ticket_Price
PNR_No
Train_No
ID
6|Page
Ticket Status Ticket_id
Confirmed
RAC
Waiting
ID
Payment ID
Ticket_Id
Paid_Amt
Pay_Date
Pay_Desc
7|Page
ER Diagram
8|Page
Schema Diagram
9|Page
Creating Commands
Create table User( ID int primary key, First_Name varchar(50) , Middle_name varchar(50),
Last_name varchar(50), Gender char, Age int, Mobile_No. varchar(50), City varchar(50),
State varchar(50), Pin_Code varchar(20));
Create table Train( Train_No. int primary key, Train_Name varchar(50), Capacity int,
Train_Desc. Varchar(50), Destination varchar(50); Arrival_Time varchar(50) );
Create table Station( Train_No. int, Station_No. primary key varchar(50), Arrival_Time
varchar(50); Hault varchar(50), Departure varchar(50) );
Create table Ticket ( Ticket_Id int primary key, First_Name varchar(50), Ticket_Price
varchar(50), PNR_No. int , Train_No. int, ID int );
Create table Ticket_Status ( Ticket_Id int primary key, Confirmed varchar(50), RAC
varchar(50), Waiting varchar(50) , ID int);
Create table Payment ( Pay_date int, Ticket_Id int, Paid_Amt. int, ID int, Pay_Desc.
Varchar(50) );
Create table Travels _In ( ID int foreign key, Train_No. Int foreign key, Constraint foreign
key(ID) references User(ID), Constraint foreign key(Train_No.) references Train(Train_No.) );
Create table Books & Cancel ( ID int ,First_Name varchar(50), Constraint foreign key (ID)
references User(ID), Constraint foreign key (ID) references Ticket(ID) );
Create table exist Start (Train_No. int , Arrival_time varchar(50), Constraint foreign
key(train_no.) references Train(train_no.) );
Create table Shows (Ticket_Id int, ID int, Constraint foreign key(Ticket_Id) references
Ticket(Ticket_Id), Constraint foreign key(Ticket_Id ) references Ticket_Status( Ticket_Id) );
10 | P a g e
1. CREATING AND DISPLAYING MAIN TABLES
CREATE TABLE 'Payment' ( Pay_date varchar(50), Ticket_Id int, Paid_Amt int, ID int,
Pay_Desc Varchar(50) );
11 | P a g e
( '23/06/2021' , 109900 ,200 , 1 , 'UPI '),
( '21/05/2020' , 109834 , 300 , 2, 'BY cash'),
( '13/02/2020' , 106734 , 156 , 3, 'Net Banking'),
( '25/ 06/2021' , 109823 ,799 ,4 ,'UPI' ),
( '09/08/2019' , 109992 , 425 , 5 , 'BY cash'),
( '30/04/2020' , 107843 , 677, 6,'UPI'),
( '17/03/2021' , 102235, 500, 7, 'Net Banking'),
( '20/09/2019' , 109978, 200, 8 , 'Net Banking'),
( '05/02/2020' , 105588, 600, 9, 'UPI'),
( '29/03/2021' , 107823, 300, 10,'UPI'),
( '06/03/2020', 106721, 800, 11, 'BY cash'),
( '05/04/2021', 102344 , 500, 12, 'UPI');
12 | P a g e
('Frontier Express', 4563,'Second Class', 'Rajasthan', '16:00:00', 800),
('Frontier Express', 5678, 'First Class', 'Delhi', '10:00:00', 800),
('Rajdhani Express', 3232, 'Second Class','Mumbai','09:00:00', 2300);
13 | P a g e
CREATE TABLE 'Ticket' ( Ticket_Id int primary key, Name varchar(50), Ticket_Price
varchar(50), PNR_No int , Train_No int, ID int );
14 | P a g e
CREATE TABLE 'Ticket_Status' ( Ticket_Id int primary key, Confirmed varchar(50),
RAC varchar(50), Waiting varchar(50) , ID int);
(109900,'Yes','No','No',1),
(109834,'No','Yes','No',2),
(106734,'No','Yes','No',3),
(109823,'No','No','Yes',4),
(109992,'Yes','No','No',5),
(107843,'No','No','Yes',6),
(102235,'No','Yes','No',7),
(109978,'Yes','No','No',8),
(105588,'No','No','Yes',9),
(107823,'Yes','No','No',10),
(106721,'No','Yes','No',11),
(102344,'Yes','No','No',12);
15 | P a g e
SELECT * FROM Ticket_Status;
(109900,1),
( 109834,2),
( 106734,3),
( 109823,4),
( 109992,5),
( 107843,6),
(102235,7),
(109978,8),
(105588,9),
(107823,10),
(106721,11),
(102344,12);
16 | P a g e
SELECT * FROM Shows;
Create table 'Travels_In' (ID int NOT NULL, Train_No int NOT NULL ,
FOREIGN KEY(ID) REFERENCES User(ID),
FOREIGN KEY(Train_No) REFERENCES Train(Train_No) );
( 1, 1678),
( 2 , 2341),
( 3, 9043),
(4, 8754),
( 5 ,2312),
(6 , 5632),
(7 , 9076),
(8 , 7823),
(9 , 3452),
(10, 8954),
(11, 5634),
(12, 9078);
17 | P a g e
SELECT * FROM Travels_In;
(1,'Chandigarh'),
(2,'Delhi'),
(3,'Jaipur'),
(4,'Lucknow'),
(5,'Mumbai'),
(6,'Allahabad'),
(7,'Kolkata'),
(8,'Patna'),
(9,'Madras'),
(10,'Jammu Kashmir'),
(11,'Rajasthan'),
(12,'Madhya Pradesh');
18 | P a g e
SELECT * FROM Books_Cancels;
19 | P a g e
CREATE TABLE 'Start' (Train_No int ,
Arrival_Time varchar(50),
FOREIGN KEY(Train_No) REFERENCES Train(Train_No) );
(1678,'10:00:00'),
(2341, '20:40:00'),
(9043, '01:00:00'),
(8754,'18:00:00'),
(2312, '10:00:00'),
(9076, '10:05:00'),
(3452, '18:00:00'),
(8954, '19:55:00'),
(5634, '01:45:00'),
(9076,'15:00:00');
20 | P a g e
3. RELATIONAL QUERIES
21 | P a g e
4. QUERIES PERFORMED
Inserting
INSERT INTO User VALUES(13 ,'Soham' ,'Singh' , 'Kundu' ,'M' ,'25' ,'8944336564' , 'Geeta
Colony' ,'Delhi', '158043');
22 | P a g e
INSERT INTO Train VALUES
('Rajgir Express', 1034,'Third Class' , 'New Delhi', '21:23:45', 625);
SELECT * FROM Train;
Updating
UPDATE User set Middle_Name='Sharma' where ID= 4;
23 | P a g e
UPDATE User set Mobile_no= '9834256148' WHERE ID= 6;
Deleting
DELETE FROM Payment WHERE ID='10';
24 | P a g e
DELETE FROM Ticket_Status WHERE ID='10';
Altering A Table
ALTER Table Train ADD COLUMN AC_Type Varchar(50);
25 | P a g e
UPDATE Train set AC_Type='NON-AC' where Train_No='3232';
Dropping
DROP TABLE Reaches;
Truncating
TRUNCATE TABLE Payment;
Renaming Tables
ALTER TABLE Train RENAME Train_Info;
26 | P a g e
Jammu Mail Express|1345|Third Class|Madras|22:00:00|2500
Delhi Jaipur Double Decker|1234|Third Class|Jaipur|22:45:00|800
Jaipur Delhi Double Decker|1453|Third Class|Patna|09:30:00|800
Delhi Chandigarh Shatabdi|1678|Second Class|Chandigarh|20:30:00|1200
Chandigarh Delhi Shatabdi|1276|First Class|Jammu Kashmir|14:00:00|1200
Ashram Express|3121|Third Class|Lucknow|05:15:00|700
Frontier Express|4563|Second Class|Rajasthan|16:00:00|800
Frontier Express|5678|First Class|Delhi|10:00:00|800
Rajdhani Express|3232|Second Class|Mumbai|09:00:00|2300
Backing up
Restoring a Database
27 | P a g e
Simple Queries, Simple Queries with Aggregate functions.
1.Average
SELECT
AVG(Paid_Amt)
FROM
Payment;
454.75
2. Maximum
SELECT
MAX(Capacity)
FROM
Train_Info;
3600
3.Minimum
SELECT
MIN(Capacity)
FROM
Train_Info
600
4. Count
SELECT
COUNT(*)
FROM
products;
12
28 | P a g e
Queries with Aggregate functions(group by and having clause)
SELECT
Ticket_Id, AVG(Paid_Amt)
FROM
Payment
GROUP BY Ticket_Id;
SELECT
Train_No, SUM(Capacity)
FROM
Train_Info
GROUP BY Train_No;
29 | P a g e
SELECT COUNT(ID), State
FROM User
GROUP BY State
HAVING COUNT(ID) > 3
ORDER BY COUNT(ID) DESC;
5|Delhi
Allahabad|65
Chandigarh|67
Delhi|68
Jaipur|74
Jammu Kashmir|74
Kolkata|75
Lucknow|76
Madras|77
Madhya Pradesh|77
Mumbai|77
Patna|80
Rajasthan|82
30 | P a g e