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. The record of train includes its number, name, source, destination, and days on which it is available, whereas record of train status includes dates for which tickets can be booked, total number of seats available, and number of seats already booked. The database has been developed and tested on the Oracle.
Passengers can book their tickets for the train in which seats are available. For this, passenger has 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 ID is generated which is stored along with other details of the passenger. After all the available tickets are booked, certain number of tickets are booked with waiting status. If waiting lot is also finished, then tickets are not booked and a message of non-availability of seats is displayed.
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. With this, the first ticket with waiting status also gets confirmed.
Since the reservation system is very large in reality, it is not feasible to develop the case study to that extent and prepare documentation at that level. Therefore, a small sample case study has been created to demonstrate the working of the reservation system. To implement this sample case study, some assumptions have been made, which are as follows:
Tables and procedures that will be created are as follows:
Constraint: The train number is unique.
Constraint: Train number should exist in TrainList
table.
Constraint: Ticket ID is unique and the train number should exist in TrainList
table.
Train_Status
table. If the desired category is AC, then total number of AC seats and number of booked AC seats are compared in order to find whether ticket can be booked or not. Similarly, it can be checked for the general category. If ticket can be booked, then passenger details are read and stored in the Passenger
table.Passenger
table. If the record exists, it is deleted from the table. After deleting the record (if it is confirmed), first record with waiting status for the same train and same category are searched from the Passenger
table and its status is changed to confirm.TrainList(TrainNumber, TrainName, Source, Destination, AC_Fair, GEN_Fair, MonAvailable, TueAvailable, WedAvailable, ThuAvailable, FriAvailable, SatAvailable, SunAvailable)
Train_Status(TrainNumber, TrainDate, AC_Seat, GEN_Seat, B_AC_ Seat, B_GEN_Seat)
Passenger(T_ID, TrainNumber, BookedDate, Name, Age, Sex, Address, Status, Category)
CREATE TABLE TrainList
( TrainNumber NUMERIC(4), TrainName VARCHAR(20), Source VARCHAR(20), Destination VARCHAR(20), AC_Fair NUMERIC(10), GEN_Fair NUMERIC(10), MonAvailable VARCHAR(1), TueAvailable VARCHAR(1), WedAvailable VARCHAR(1), ThuAvailable VARCHAR(1), FriAvailable VARCHAR(1), SatAvailable VARCHAR(1), SunAvailable VARCHAR(1), PRIMARY KEY (TrainNumber) );
CREATE TABLE Train_Status
( TrainNumber NUMERIC(4), TrainDate DATE, AC_Seat NUMERIC(4), GEN_Seat NUMERIC(4), B_AC_Seat NUMERIC(4), B_GEN_Seat NUMERIC(4), FOREIGN KEY (TrainNumber) REFERENCES TrainList(TrainNumber) );
CREATE TABLE Passenger
( T_ID VARCHAR(15), TrainNumber NUMERIC(4), BookedDate DATE, Name VARCHAR(20), Age NUMERIC(3), Sex VARCHAR(1), Address VARCHAR(35), Status VARCHAR(1), Category VARCHAR(10), PRIMARY KEY (T_ID), FOREIGN KEY (TrainNumber) REFERENCES TrainList(TrainNumber) );
DECLARE TN NUMERIC(4); DT DATE; CAT VARCHAR(10); ST VARCHAR(1);
CURSOR getTrain IS SELECT * FROM Train_Status WHERE TrainNumber=TN AND TrainDate=DT; trec Train_Status%ROWTYPE;
BEGIN
DBMS_OUTPUT.PUT_LINE(‘READING VALUES’); TN := &TN; DT := ‘&DT’; CAT := ‘&CAT’;
OPEN getTrain; LOOP FETCH getTrain INTO trec; EXIT WHEN getTrain%NOTFOUND; IF(CAT = ‘AC’)THEN IF(trec.AC_Seat-trec.B_AC_Seat)>0 THEN ST := ‘C’; DBMS_OUTPUT.PUT_LINE(‘Seat Confirmed’); ELSIF(trec.AC_Seat-trec.B_AC_Seat) > -2 THEN ST := ‘W’; DBMS_OUTPUT.PUT_LINE(‘Seat Waiting’); ELSE DBMS_OUTPUT.PUT_LINE(‘Seat Not Available’); EXIT; END IF; IF ST = ‘C’ OR ST = ‘W’ THEN UPDATE Train_Status SET B_AC_Seat = B_AC_Seat + 1 WHERE TrainNumber = TN and TrainDate=DT; END IF; ELSIF(CAT = ‘GEN’) THEN IF(trec.GEN_Seat-trec.B_GEN_Seat)>0 THEN ST := ‘C’; DBMS_OUTPUT.PUT_LINE(‘Seat Confirmed’); ELSIF(trec.GEN_Seat-trec.B_GEN_Seat) > -2 THEN ST := ‘W’; DBMS_OUTPUT.PUT_LINE(‘Seat Waiting’); ELSE DBMS_OUTPUT.PUT_LINE(‘Seat Not Available’); EXIT; END IF; IF ST = ‘C’ OR ST = ‘W’ THEN UPDATE Train_Status SET B_GEN_Seat = B_GEN_Seat+1 WHERE TrainNumber = TN and TrainDate=DT; END IF; ELSE DBMS_OUTPUT.PUT_LINE(‘Invalid Category’); END IF; IF ST = ‘C’ OR ST = ‘W’ THEN INSERT INTO Passenger VALUES(‘&T_ID’, TN, DT, ‘&Name’, &Age, ‘&Sex’, ‘&Address’, ST, CAT); END IF; END LOOP; CLOSE getTrain; END ;/
DECLARE
TID VARCHAR(15); TN NUMERIC(4); DT DATE; CAT VARCHAR(10); ST VARCHAR(1); CURSOR Get_waiting IS SELECT * FROM Passenger WHERE (Status = ‘W’ AND TrainNumber = TN AND BookedDate = DT AND Category = CAT) FOR UPDATE OF Status; prec Passenger%ROWTYPE;
BEGIN
TID := ‘&TID’; SELECT TrainNumber, BookedDate, Status, Category INTO TN, DT, ST, CAT FROM Passenger WHERE T_ID = TID; IF TN IS NOT NULL THEN DELETE FROM Passenger WHERE T_ID = TID; IF CAT = ‘AC’ THEN UPDATE Train_Status SET B_AC_Seat = B_AC_Seat - 1 WHERE TrainNumber=TN AND TrainDate=DT; ELSE UPDATE Train_Status SET B_GEN_Seat = B_GEN_Seat - 1 WHERE TrainNumber=TN AND TrainDate=DT; END IF; DBMS_OUTPUT.PUT_LINE(‘TICKET CANCELLED’); ELSE DBMS_OUTPUT.PUT_LINE(‘NO SUCH BOOKING EXISTS’); END IF; IF (ST = ‘C’) THEN OPEN Get_waiting; FETCH Get_waiting INTO prec; IF Get_waiting%FOUND THEN UPDATE Passenger SET Status = ‘C’ WHERE CURRENT OF Get_waiting; END IF; CLOSE Get_waiting; END IF;
END ; /
INSERT INTO TrainList
VALUES (2444, ‘Bhubaneswar Rajdhani’, ‘New Delhi’, ‘Bhubaneswar’, 2250, 1850, ‘Y’, ‘Y’, ‘N’, ‘Y’, ‘Y’, ‘Y’, ‘N’);
SELECT *
FROM TrainList;
SELECT TrainNumber, TrainName, AC_Fair, GEN_Fair
FROM TrainList WHERE Source = ‘New Delhi’ AND Destination = ‘Puri’;
INSERT INTO Train_Status
VALUES (2444, ‘02-MAY-2009’, 10, 10, 0, 0);
SELECT *
FROM Train_Status WHERE TrainNumber = 2444;
SQL> @e:RailwayReservationBooking
Enter value for tn: 2444 old 14: TN := &TN; new 14: TN := 2444; Enter value for dt: 02-MAY-2009 old 15: DT := ‘&DT’; new 15: DT := ‘02-MAY-2009’; Enter value for cat: AC old 16: CAT := ‘&CAT’; new 16: CAT := ‘AC’; Enter value for t_id: 3 Enter value for name: PREETI Enter value for age: 29 Enter value for sex: F Enter value for address: ROHINI old 73: INSERT INTO Passenger VALUES(‘&T_ID’, TN, DT, ‘&Name’, &Age, ‘&Sex’, ‘&Address’, ST, CAT); new 73: INSERT INTO Passenger VALUES(‘3’, TN, DT, ‘PREETI’, 29, ‘F’, ‘ROHINI’, ST, CAT); READING VALUES Seat Confirmed
SQL> @e:RailwayReservationBooking
Enter value for tn: 2444 old 14: TN := &TN; new 14: TN := 2444; Enter value for dt: 02-MAY-2009 old 15: DT := ‘&DT’; new 15: DT := ‘02-MAY-2009’; Enter value for cat: AC old 16: CAT := ‘&CAT’; new 16: CAT := ‘AC’; Enter value for t_id: 4 Enter value for name: PREMASHIS Enter value for age: 26 Enter value for sex: M Enter value for address: MAYURVIHAR old 73: INSERT INTO Passenger VALUES(‘&T_ID’, TN, DT, ‘&Name’, &Age, ‘&Sex’, ‘&Address’, ST, CAT); new 73: INSERT INTO Passenger VALUES(‘4’, TN, DT, ‘PREMASHIS’, 26, ‘M’, ‘MAYURVIHAR’, ST, CAT); READING VALUES Seat Confirmed
SQL> @e:RailwayReservationBooking
Enter value for tn: 2444 old 14: TN := &TN; new 14: TN := 2444; Enter value for dt: 02-MAY-2009 old 15: DT := ‘&DT’; new 15: DT := ‘02-MAY-2009’; Enter value for cat: AC old 16: CAT := ‘&CAT’; new 16: CAT := ‘AC’; Enter value for t_id: 12 Enter value for name: UMA Enter value for age: 26 Enter value for sex: F Enter value for address: SUBHASHPLACE old 73: INSERT INTO Passenger VALUES(‘&T_ID’, TN, DT, ‘&Name’, &Age, ‘&Sex’, ‘&Address’, ST, CAT); new 73: INSERT INTO Passenger VALUES(‘12’, TN, DT, ‘UMA’, 26, ‘F’, ‘SUBHASHPLACE’, ST, CAT); READING VALUES Seat Waiting
SQL> @e:RailwayReservationBooking
Enter value for tn: 2444 old 14: TN := &TN; new 14: TN := 2444; Enter value for dt: 02-MAY-2009 old 15: DT := ‘&DT’; new 15: DT := ‘02-MAY-2009’; Enter value for cat: AC old 16: CAT := ‘&CAT’; new 16: CAT := ‘AC’; Enter value for t_id: 13 Enter value for name: MEENU Enter value for age: 26 Enter value for sex: F Enter value for address: PITAMPURA old 73: INSERT INTO Passenger VALUES(‘&T_ID’, TN, DT, ‘&Name’, &Age, ‘&Sex’, ‘&Address’, ST, CAT); new 73: INSERT INTO Passenger VALUES(‘13’, TN, DT, ‘MEENU’, 26, ‘F’, ‘PITAMPURA’, ST, CAT); READING VALUES Seat Waiting
SQL> @e:RailwayReservationBooking
Enter value for tn: 2444 old 14: TN := &TN; new 14: TN := 2444; Enter value for dt: 02-MAY-2009 old 15: DT := ‘&DT’; new 15: DT := ‘02-MAY-2009’; Enter value for cat: AC old 16: CAT := ‘&CAT’; new 16: CAT := ‘AC’; Enter value for t_id: 14 Enter value for name: KHYATI Enter value for age: 26 Enter value for sex: F Enter value for address: PITAMPURA old 73: INSERT INTO Passenger VALUES(‘&T_ID’, TN, DT, ‘&Name’, &Age, ‘&Sex’, ‘&Address’, ST, CAT); new 73: INSERT INTO Passenger VALUES(‘14’, TN, DT, ‘KHYATI’, 26, ‘F’, ‘PITAMPURA’, ST, CAT); READING VALUES Seat Not Available
SELECT *
FROM Passenger WHERE TrainNumber = 2444;
SQL> @E:RailwayReservationCancel
Enter value for tid: 9 old 11: TID := ‘&TID’; new 11: TID := ‘9’; TICKET CANCELLED
SELECT *
FROM Passenger WHERE TrainNumber = 2444;
SELECT *
FROM Train_Status WHERE TrainNumber = 2444;
NOTE To display the output messages of the procedures, the command Set Serveroutput On
is given before executing the procedures.