Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 32

INDIRA GANDHI DELHI TECHNICAL UNIVERSITY FOR WOMEN

Railway Management System

Department of Computer Science Engineering

Database Management System

B-TECH – 3rd Semester

PROJECT REPORT

By

Khyati Singh
(05001012020)
Anushka
(05201012020)
Harshita Prajapati
(03401012020)

INDIRA GANDHI DELHI TECHNICAL UNIVERSITY


FOR WOMEN
NEW DELHI – 110006

NOVEMBER 2021

1|Page
INDIRA GANDHI DELHI TECHNICAL UNIVERSITY FOR WOMEN

INDEX

Abstract……………………………………………………………………3

Introduction…………………………………………………….……….…4

Project Description…………………………………………………………5

List of Entities and Attributes………………………………………………6

ER Diagram…………………………………………………………………8

Schema Diagram………………………..………………………………..…9

Creating Commands………………………………………………………..10

1. Creating and displaying main tables………………………………..11


2. Creating and displaying Relation Tables…………….……………..16
3. Relational Queries ……………………...…………………………..21

2|Page
INDIRA GANDHI DELHI TECHNICAL UNIVERSITY FOR WOMEN

Abstract

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.

This project contains Introduction to the Railways reservation system It is the


computerized system of reserving the seats of train seats in advanced. It is
mainly used for long route. On-line reservation has made the process for the
reservation of seats very much easier than ever before.

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.

3|Page
INDIRA GANDHI DELHI TECHNICAL UNIVERSITY FOR WOMEN

Introduction

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.

The main purpose of maintaining database for Railway Reservation System is to


reduce the manual errors involved in the booking and canceling of tickets and
make it convenient for the customers and providers to maintain the data about
their customers and also about the seats available at them. Due to automation
many loopholes that exist in the manual maintenance of the records can be
removed. The speed of obtaining and processing the data will be fast. For future
expansion the proposed system can be web enabled so that clients can make
various enquiries about trains between stations. Due to this, sometimes a lot of
problems occur and they are facing many disputes with customers. To solve the
above problem, we design a data base which includes customer details.
availability of seats in trains. no of trains and their details.

4|Page
INDIRA GANDHI DELHI TECHNICAL UNIVERSITY FOR WOMEN

Project Description

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
INDIRA GANDHI DELHI TECHNICAL UNIVERSITY FOR WOMEN

List of Entities and Attributes

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
INDIRA GANDHI DELHI TECHNICAL UNIVERSITY FOR WOMEN

Ticket Status Ticket_id


Confirmed
RAC
Waiting
ID

Payment ID
Ticket_Id
Paid_Amt
Pay_Date
Pay_Desc

ER Diagram
7|Page
INDIRA GANDHI DELHI TECHNICAL UNIVERSITY FOR WOMEN

Schema Diagram
8|Page
INDIRA GANDHI DELHI TECHNICAL UNIVERSITY FOR WOMEN

Creating Commands
9|Page
INDIRA GANDHI DELHI TECHNICAL UNIVERSITY FOR WOMEN

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 Reaches ( Train_No. int , Arrival_time varchar(50), Constraint foreign


key(train_no.) references Train(train_no.) );

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) );

1. CREATING AND DISPLAYING MAIN TABLES

10 | P a g e
INDIRA GANDHI DELHI TECHNICAL UNIVERSITY FOR WOMEN

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));

Insert into 'User' ('ID','First_Name','Middle_Name','Last_Name',


'Gender','Age','Mobile_no','City','State','Pin_Code') VALUES

(1 ,'Anushka' , 'Kumari' ,'Gupta' , 'F' , 20 , '9890888666' , 'Badarpur' , 'Delhi' ,'110044'),


(2 ,'Harshita' ,'Kumari' , 'Prajapati' ,'F' ,'19' ,'9022336760' , 'Roshanara' ,'Delhi', '110007'),
(3 ,'Khyati' ,'Kumari' , 'Singh' ,'F' ,'19' ,'9022336563' , 'Rohini' ,'Delhi', '110087'),
(4 ,'Geeta' ,'Singh' , 'Rajan' ,'F' ,'22' ,'9024566760' , 'Shahadra' ,'Haryana', '11054'),
(5 ,'Neha' ,'Kumari' , 'Sood' ,'F' ,'21' ,'9992336760' , 'Sarita Vihar' ,'Haryana', '156007'),
(6 ,'Muskaan' ,'sharma' , 'Ranjan' ,'F' ,'20' ,'9023676760' , 'Dwarka' ,'Punjab', '113407'),
(7 ,'Aditi' ,'Yadav' , 'Pran' ,'F' ,'34' ,'9022336444' , 'Lajpat Nagar' ,'Punjab', '114507'),
(8 ,'Akash' ,'Kumar' , 'Baghel' ,'M' ,'24' ,'9342336760' , 'Nehru place' ,'Delhi', '112307'),
(9 ,'Sarthak' ,'Sinha' , 'Dagar' ,'M' ,'20' ,'8042336760' , 'Sangam Vihar' ,'Haryana', '101007'),
(10 ,'Shiv' ,'Kumar' , 'Bharti' ,'M' ,'19' ,'9022356112' , 'Dwarka' ,'Delhi', '110067'),
(11 ,'Mihir' ,'Krishan' , 'Gautam' ,'M' ,'30' ,'9022311883' , 'Bareilly' ,'UP', '110627'),
(12 ,'Amit' ,'Singh' , 'Roshan' ,'M' ,'23' ,'8944336760' , 'Bareilly' ,'UP', '158007');

SELECT * FROM User;

CREATE TABLE 'Payment' ( Pay_date varchar(50), Ticket_Id int, Paid_Amt int, ID int,
Pay_Desc Varchar(50) );

INSERT INTO 'Payment' ( 'Pay_date' , 'Ticket_Id' , 'Paid_Amt' , 'ID' , 'Pay_Desc' ) VALUES

( '23/06/2021' , 109900 ,200 , 1 , 'UPI '),


( '21/05/2020' , 109834 , 300 , 2, 'BY cash'),

11 | P a g e
INDIRA GANDHI DELHI TECHNICAL UNIVERSITY FOR WOMEN

( '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');

SELECT * FROM Payment;

CREATE TABLE 'Train'(Train_Name varchar(50),


Train_No int primary key,Train_Desc varchar(50),
Destination varchar(50), Arrival_Time varchar(50),Capacity int);

INSERT INTO 'Train' ('Train_Name','Train_No', 'Train_Desc', 'Destination',


'Arrival_Time', 'Capacity') VALUES

('Ashram Express', 1021,'Third Class' , 'Kolkata', '21:30:00', 700),


('Shatabdi Express', 1089, 'First Class','Allahabad', '16:30:00', 600),
('Harijan Express', 1290, 'Second Class', 'Madhya Pradesh', '13:00:00', 3600),
('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);

12 | P a g e
INDIRA GANDHI DELHI TECHNICAL UNIVERSITY FOR WOMEN

SELECT * FROM Train;

CREATE TABLE 'Station'(Train_No int, Station_No varchar(50) primary key, Name


varchar(50),

Arrival_Time varchar(50), Hault varchar(50), Departure varchar(50));


INSERT INTO 'Station' ('Train_No', 'Station_No','Name', 'Arrival_Time', 'Hault', 'Departure')
VALUES

( 1678 , 101, 'Chandigarh','10:00:00', '00:00:30', '22:05:00'),


( 5678 , 120, 'Delhi', '20:40:00', '00:00:10' , '18:00:00'),
( 1234 , 371, 'Jaipur','01:00:00','00:00:25' ,'10:00:00'),
( 3121 , 230, 'Lucknow','18:00:00', '00:00:35','03:05:00'),
( 3232 , 123, 'Mumbai','10:00:00', '00:00:28' ,'18:00:00'),
( 1089 , 110, 'Allahbad', '10:35:00','00:00:35' ,'22:18:00'),
( 1021, 126, 'Kolkata', '10:05:00','00:00:20' ,'18:55:00'),
(1453, 119, 'Patna','15:00:00', '00:00:10','20:00:00'),
( 1345, 220, 'Madras','18:00:00', '00:00:30' ,'18:00:00'),
( 1276 ,189, 'Jammu Kashmir','19:55:00', '00:00:10','11:20:00'),
( 4563 ,773, 'Rajasthan','01:45:00', '00:00:25' ,'12:00:00'),
( 1290 ,171, 'Madhya Pradesh','15:00:00','00:00:15' ,'10:00:00');

SELECT * FROM Station;

13 | P a g e
INDIRA GANDHI DELHI TECHNICAL UNIVERSITY FOR WOMEN

CREATE TABLE 'Ticket' ( Ticket_Id int primary key, Name varchar(50), Ticket_Price
varchar(50), PNR_No int , Train_No int, ID int );

INSERT INTO 'Ticket'( 'Ticket_Id' , 'Name' ,'Ticket_Price','PNR_No','Train_No','ID' )


VALUES

( 109900 , 'Chandigarh', '200','2346712891','1678' , 1),


( 109834 , 'Delhi', '300' ,'4566278123' ,'2341', 2),
( 106734 , 'Jaipur', '156' ,'3467345672' ,'9043', 3),
( 109823 , 'Lucknow', '799', '7635423112', '8754', 4),
( 109992 , 'Mumbai', '425', '5467345689', '2312',5),
( 107843 , 'Allahabad', '677', '7823456129','5632',6),
(102235, 'Kolkata' , '500', '8945323127', '9076', 7),
(109978 , 'Patna' ,'200', '9823415643', '7823',8),
(105588 ,'Madras' , '600', '6723412453', '3452', 9),
(107823 , 'Jammu Kashmir' ,'300', '2341237845', '8954',10),
(106721 , 'Rajasthan' ,'800', '7448545324' , '5634', 11),
(102344 , 'Madhya Pradesh', '500', '5634234891' ,'9078', 12);

SELECT * FROM Ticket;

14 | P a g e
INDIRA GANDHI DELHI TECHNICAL UNIVERSITY FOR WOMEN

CREATE TABLE 'Ticket_Status' ( Ticket_Id int primary key, Confirmed varchar(50),


RAC varchar(50), Waiting varchar(50) , ID int);

INSERT INTO 'Ticket_Status'('Ticket_Id', 'Confirmed', 'RAC','Waiting','ID') VALUES

(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
INDIRA GANDHI DELHI TECHNICAL UNIVERSITY FOR WOMEN

SELECT * FROM Ticket_Status;

2. CREATING RELATION TABLES

CREATE TABLE 'Shows' (


Ticket_Id int NOT NULL,
ID int NOT NULL,
FOREIGN KEY (Ticket_Id) REFERENCES Ticket(Ticket_Id)
FOREIGN KEY (Ticket_Id ) REFERENCES Ticket_Status( Ticket_Id) );

INSERT INTO 'Shows'('Ticket_Id','ID')VALUES

(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
INDIRA GANDHI DELHI TECHNICAL UNIVERSITY FOR WOMEN

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) );

INSERT INTO 'Travels_In' ( 'ID','Train_No') VALUES

( 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
INDIRA GANDHI DELHI TECHNICAL UNIVERSITY FOR WOMEN

SELECT * FROM Travels_In;

CREATE TABLE 'Books_Cancels' ( ID int NOT NULL,


First_Name varchar(50) NOT NULL,
FOREIGN KEY (ID) REFERENCES User(ID),
FOREIGN KEY (ID) REFERENCES Ticket(ID) );

INSERT INTO 'Books_Cancels'('ID','First_Name') VALUES

(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
INDIRA GANDHI DELHI TECHNICAL UNIVERSITY FOR WOMEN

SELECT * FROM Books_Cancels;

CREATE TABLE 'Reaches' ( Train_No int ,


Arrival_Time varchar(50),
FOREIGN KEY(Train_No) REFERENCES Train(Train_No) );

INSERT INTO 'Reaches'('Train_No','Arrival_Time') VALUES


(2341, '20:40:00'),
(9043, '01:00:00'),
(8754,'18:00:00'),
(2312, '10:00:00'),
(5632, '10:35:00' ),
(9076, '10:05:00'),
(7823, '15:00:00' ),
(3452, '18:00:00'),
(8954, '19:55:00'),
(5634, '01:45:00');

SELECT * FROM Reaches;

19 | P a g e
INDIRA GANDHI DELHI TECHNICAL UNIVERSITY FOR WOMEN

CREATE TABLE 'Start' (Train_No int ,


Arrival_Time varchar(50),
FOREIGN KEY(Train_No) REFERENCES Train(Train_No) );

INSERT INTO 'Start'('Train_No','Arrival_Time') VALUES

(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');

SELECT * FROM 'Start';

20 | P a g e
INDIRA GANDHI DELHI TECHNICAL UNIVERSITY FOR WOMEN

3. RELATIONAL QUERIES

SELECT Arrival_Time FROM 'Start'


INTERSECT
SELECT Arrival_Time FROM 'Reaches' ;

SELECT Arrival_Time FROM 'Start'


UNION
SELECT Arrival_Time FROM 'Reaches' ;

21 | P a g e
INDIRA GANDHI DELHI TECHNICAL UNIVERSITY FOR WOMEN

22 | P a g e
INDIRA GANDHI DELHI TECHNICAL UNIVERSITY FOR WOMEN

23 | P a g e
INDIRA GANDHI DELHI TECHNICAL UNIVERSITY FOR WOMEN

24 | P a g e
INDIRA GANDHI DELHI TECHNICAL UNIVERSITY FOR WOMEN

4. QUERIES PERFORMED

Inserting
INSERT INTO User VALUES(13 ,'Soham' ,'Singh' , 'Kundu' ,'M' ,'25' ,'8944336564' , 'Geeta
Colony' ,'Delhi', '158043');

SELECT * FROM User;

INSERT INTO Train VALUES


('Rajgir Express', 1034,'Third Class' , 'New Delhi', '21:23:45', 625);
SELECT * FROM Train;

25 | P a g e
INDIRA GANDHI DELHI TECHNICAL UNIVERSITY FOR WOMEN

Updating
UPDATE User set Middle_Name='Sharma' where ID= 4;

SELECT * FROM User;

UPDATE User set Mobile_no= '9834256148' WHERE ID= 6;

SELECT * FROM User

26 | P a g e
INDIRA GANDHI DELHI TECHNICAL UNIVERSITY FOR WOMEN

Deleting
DELETE FROM Payment WHERE ID='10';

SELECT * FROM Payment;

DELETE FROM Ticket_Status WHERE ID='10';

SELECT * FROM Ticket_Status;

Altering A Table
ALTER Table Train ADD COLUMN AC_Type Varchar(50);

UPDATE Train set AC_Type='AC' where Train_No='1021';


UPDATE Train set AC_Type='NON-AC' where Train_No='1089';
UPDATE Train set AC_Type='AC' where Train_No='1290';
UPDATE Train set AC_Type='AC' where Train_No='1345';
UPDATE Train set AC_Type='NON-AC' where Train_No='1234';
UPDATE Train set AC_Type='AC' where Train_No='1453';

27 | P a g e
INDIRA GANDHI DELHI TECHNICAL UNIVERSITY FOR WOMEN

UPDATE Train set AC_Type='AC' where Train_No='1678';


UPDATE Train set AC_Type='NON-AC' where Train_No='1276';
UPDATE Train set AC_Type='AC' where Train_No='3121';
UPDATE Train set AC_Type='NON-AC' where Train_No='4563';
UPDATE Train set AC_Type='AC' where Train_No='5678';
UPDATE Train set AC_Type='NON-AC' where Train_No='3232';

SELECT * FROM Train;

Dropping
DROP TABLE Reaches;

SELECT *FROM 'Reaches';

Truncating
TRUNCATE TABLE Payment;

SELECT * FROM Payment;

Error: near line 234: no such table: Payment

Renaming Tables
ALTER TABLE Train RENAME Train_Info;

28 | P a g e
INDIRA GANDHI DELHI TECHNICAL UNIVERSITY FOR WOMEN

SELECT * FROM Train_Info;


Ashram Express|1021|Third Class|Kolkata|21:30:00|700
Shatabdi Express|1089|First Class|Allahabad|16:30:00|600
Harijan Express|1290|Second Class|Madhya Pradesh|13:00:00|3600
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

ALTER TABLE Train_Info;


TRUNCATE COLUMN Hault;
SELECT * INTO Hault
FROM Train_Info;

SELECT * FROM Train_Info;

Ashram Express|1021|Third Class|Kolkata|21:30:00|700


Shatabdi Express|1089|First Class|Allahabad|16:30:00|600
Harijan Express|1290|Second Class|Madhya Pradesh|13:00:00|3600
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

Restoring a Database

29 | P a g e
INDIRA GANDHI DELHI TECHNICAL UNIVERSITY FOR WOMEN

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

30 | P a g e
INDIRA GANDHI DELHI TECHNICAL UNIVERSITY FOR WOMEN

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;

31 | P a g e
INDIRA GANDHI DELHI TECHNICAL UNIVERSITY FOR WOMEN

SELECT COUNT(ID), State


FROM User
GROUP BY State
HAVING COUNT(ID) > 3
ORDER BY COUNT(ID) DESC;

5|Delhi

Queries involving – Data Functions, String Functions

SELECT Name, ASCII(Name) AS NumCodeOfFirstChar


FROM Ticket;

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

32 | P a g e

You might also like