0% found this document useful (0 votes)
204 views26 pages

DBMS Project

The document describes a database project on a citizen management system. It includes an index, acknowledgements, introduction, ER diagram showing the tables, sample SQL queries for creating and populating the tables, useful queries to retrieve information from the tables, discussion of relational model and future scope. The project aims to store and retrieve personal information of citizens using their unique ID across different departments and services.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
204 views26 pages

DBMS Project

The document describes a database project on a citizen management system. It includes an index, acknowledgements, introduction, ER diagram showing the tables, sample SQL queries for creating and populating the tables, useful queries to retrieve information from the tables, discussion of relational model and future scope. The project aims to store and retrieve personal information of citizens using their unique ID across different departments and services.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 26

Database Management System Project

Topic: CITIZEN MANAGEMENT


SYSTEM: CS593

Group no. – 48
Names: Sagnik Chattopadhyay(95)
Debdoot Biswas(96)
Subject: Database Management Systems
Laboratory
University of Engineering and Management (Kolkata)

1
INDEX:

Acknowledgement………………………………………… 3

Introduction to topic ……………………………………... 4

ER Diagram ………………………………………………. 5

Sample SQL queries ……………………………………… 6

Useful queries related to the database ………………….. 14

Relational model …………………………………………. 23

Future scope of project…………………………………… 24

Conclusion ………………………………………………… 25

Remarks ………………………………………………….. 26

2
Acknowledgement
We, Sagnik Chattopadhyay and Debdoot Biswas, would firstly like to
thank our University for providing us with the infrastructure we used to
learn about the subject. Secondly, we would thank Sukalyan Goswami
sir, HOD of Computer Science Engineering department, UEM Kolkata.
Thirdly we would love to thank our concerned subject teachers Varsha
Poddar and Subarna Sen for providing us with the project idea and
necessary study material for the project.

3
Introduction:
Citizen Management System :

The Project ‘Citizen Card System’ gives us the information about the
citizen in any country. A Citizen has unique Id to find out the personal
information in each and every department or service wherever a citizen goes.
This information can be found out by the unique Id of the citizen.

4
ER- Diagram:
Pnr P_name
Password Age
U_id

User Has Passenger

Train_id T_name Seat no.

Has Gender

Train
Has
T_id
Dept_d

Price
Arr_d
Ticket
Has
Route_id
Has Status_id

Route No_of_stop
Status

Dept_time
Start Wait_seat Booked_seat

Arr_time
Avail_seat

End

Has

Station
Station_name

Station_id

5
Sample SQL queries:

Creations:
 Users
create table users( user_id varchar2(20) primary key,
password varchar2(20) not null
);

alter table users add constraint chk1 check (lengthb(password)>=8);

 Passenger
create table passenger( pnr varchar(8) primary key,
p_name varchar2(30),
age number,
gender varchar(10),
seat_no number,
reserve_stat varchar2(10),
u_id varchar2(20) not null references users(user_id),
status_id varchar2(10) not null,
train_id varchar2(10) not null);

6
 Train Status
create table train_stat( tstatus_id varchar2(10) primary key,
wait_seat number,
avail_seat number,
booked_seat number,
train_id varchar2(10) not null);

 Train
create table train( train_id varchar2(10) primary key,
t_name varchar2(20) not null,
car_no number,
status_id varchar2(10) not null references
train_stat(tstatus_id));

alter table train_stat add constraint train_fk foreign key(train_id)


references train(train_id);

 Station
create table station( station_id varchar2(10) primary key,
station_name varchar2(30));

7
 Route

create table route( route_id varchar2(10) primary key,


from_st varchar2(10) references station(station_id),
to_st varchar2(10) references station(station_id),
arr_time varchar2(5),
depart_time varchar2(5),
no_of_stops number,
train_id varchar2(10) references train(train_id));

8
Alterations:
1. SQL>alter table train drop column status_id;
( had conflicting foreign key)
SQL>alter table train add dept_date date;
SQL> alter table train add arr_date date;

2. SQL> alter table passenger add constraint cst2 foreign key(train_id)


references train(train_id);
SQL> alter table passenger add compart_no varchar(10);

9
Insertions:
Table: Users->

insert into users values('145FG','kolkata7');


insert into users values('147L2','prithviraj');
insert into users values('22LO4','dbmsproj');

Table: Station->

insert into station values('KOL001', 'Kolkata');


insert into station values('DEL012', 'Delhi');
insert into station values('AGR234', 'Agra');
insert into station values('VSK111', 'Vishakhapatnam');
insert into station values('BOM212', 'Mumbai');
insert into station values('CHH141', 'Chennai');
insert into station values('BAN154', 'Bengaluru');

10
Table: Train->

insert into train values('HWDLJNS10','Janashatabdi',20);


insert into train values('AGVKDU11','Duranta',15);
insert into train values('HWBMBE45','Bombay Express',16);
insert into train values('CHDLRD14','Rajdhani',20);
insert into train values('HWDLRD10','Rajdhani',20);
insert into train values('BMDLRD74','Rajdhani',20);
insert into train values('HWDLJNS12','Janashatabdi',20);
insert into train values('BMDLRD84','Rajdhani',20);

Table: Train_stat->

insert into train_stat values('ST100',0,1000,2000,'HWDLJNS10');


insert into train_stat values('ST101',500,0,2500,'AGVKDU11');
insert into train_stat values('ST102',0,400,2000,'HWBMBE45');
insert into train_stat values('ST103',0,40,2000,'CHDLRD14');
insert into train_stat values('ST104',544,0,2500,'HWDLRD10');
insert into train_stat values('ST105',40,0,2080,'BMDLRD74');
insert into train_stat values('ST106',0,200,2080,'HWDLJNS12');
insert into train_stat values('ST107',40,0,2600,'BMDLRD84');

11
Table: Route->

insert into route


values('RT100','KOL001','DEL012','00:45','14:50',26,'HWDLJNS10');
insert into route
values('RT101','KOL001','DEL012','17:45','08:15',26,'HWDLJNS12');
insert into route
values('RT102','KOL001','DEL012','21:45','06:50',10,'HWDLRD10');
insert into route
values('RT103','AGR234','VSK111','17:45','10:15',30,'AGVKDU11');
insert into route
values('RT104','KOL001','BOM212','15:10','16:50',33,'HWBMBE45');
insert into route
values('RT105','CHH141','DEL012','02:25','21:15',12,'CHDLRD14');
insert into route
values('RT106','BOM212','DEL012','17:15','04:50',11,'BMDLRD74');
insert into route
values('RT107','BOM212','DEL012','23:45','08:45',10,'BMDLRD84');

12
Table: Passenger->

insert into passenger


values('ADM101','Prithviraj',20,'Male','140','Booked','145FG','HWDLRD
10');
insert into passenger
values('ADM102','Prasad',23,'Male','141','Booked','145FG','HWDLRD10')
;

Table: Ticket->

insert into ticket values('T102','ADM102',700);


insert into ticket values('T101','ADM101',600);

13
Useful SQL queries related to the database:

1. Passengers booked by specific user id:


A. SQL> select * from passenger where u_id = '145FG';

2. Trains going to Delhi:


A. SQL> select train_id,to_st,t_name from route natural join train where
to_st = (select station_id from station where station_name = 'Delhi');

3. Trains starting from Kolkata;


A. SQL> select train_id,to_st,t_name from route natural join train where
from_st = (select station_id from station where station_name = 'Kolkata');

14
4. Trains starting from Kolkata going to Delhi:
A. SQL> select train_id,to_st,t_name from route natural join train where
from_st = (select station_id from station where station_name = 'Kolkata')
and to_st = (select station_id from station where station_name =
'Delhi');

5. Details of passengers going from Kolkata to Delhi:


A. SQL> select pnr, p_name, age , gender , train_id from passenger
natural join train natural join route where from_st = (select station_id
from station where station_name = 'Kolkata') and to_st = (select
station_id from station where station_name = 'Delhi');

6. Trains having zero vacancy:


A. SQL> select train_id,t_name from train natural join train_stat where
wait_seat > 0;

7. Stations connected via train named Rajdhani:


A. SQL> select from_st, to_st from route natural join train where t_name
= 'Rajdhani';

15
8. status of the trains going from Kolkata:
A. SQL> select train_id, wait_seat, avail_seat, booked_seat from route
natural join (train natural join train_stat) where from_st = (select
station_id from station where station_name = 'Kolkata');

9. Status of trains reaching Delhi:


A. SQL> select train_id, wait_seat, avail_seat, booked_seat from route
natural join (train natural join train_stat) where to_st = (select station_id
from station where station_name = 'Delhi');

10. No. of train cars in Rajdhanis along with stations :


A. SQL> select train_id, t_name, car_no, from_st , to_st from train
natural join route where t_name = 'Rajdhani';

11. No. of stops of trains named Janashatabdi:


A. SQL> select train_id, t_name, no_of_stops , from_st , to_st from train
natural join route where t_name = 'Janashatabdi';

16
12. No. of stops of trains connecting from Kolkata to Delhi:
A. SQL> select train_id, t_name, no_of_stops , from_st , to_st from train
natural join route where to_st = (select station_id from station where
station_name = 'Delhi') and from_st = (select station_id from station
where station_name = 'Kolkata') order by no_of_stops asc;

13. Arrival time of trains connect from Kolkata to Delhi:


A. SQL> select train_id, t_name, arr_time , from_st , to_st from train
natural join route where to_st = (select station_id from station where
station_name = 'Delhi') and from_st = (select station_id from station
where station_name = 'Kolkata') order by arr_time asc;

14. Details of trains leaving from Mumbai or from Chennai:


A. SQL> select train_id, t_name, arr_time, depart_time, from_st , to_st
from train natural join route where from_st = (select station_id from
station where station_name = 'Mumbai') or from_st = (select station_id
from station where station_name = 'Chennai');

15. Trains which have less than 20 stops:


A. SQL> select train_id, t_name, no_of_stops , from_st , to_st from train
natural join route where no_of_stops < 20;

17
16. Passengers with ticket price more than 600 (inner join):
A. SQL> select passenger.pnr, p_name , train_id, ticket_id from
passenger, ticket where passenger.pnr = ticket.pnr and price >600 ;

17. Cities from which Rajdhani leaves (outer join left):


A. SQL> select distinct station_name from train natural join route left
join station on route.from_st = station.station_id where t_name =
'Rajdhani';

18. Trains with more than 100 on waiting seats:


A. SQL> select train_id, t_name, wait_seat from train natural join
train_stat where wait_seat > 100;

19. Trains which have available seats:


A. SQL> select train_id, t_name, avail_seat from train natural join
train_stat where avail_seat > 0;

18
20. Total seats in each trains:
A. SQL> select train_id, (wait_seat+avail_seat+booked_seat)
TOTAL_SEATS from train_stat;

21. Average number of seats in Rajdhani:


A. SQL> select avg(wait_seat+avail_seat+booked_seat) AVG_seats from
train_stat natural join train where t_name = 'Rajdhani';

22. Available seats on trains going from Kolkata to Delhi:


A. SQL> select train_id,t_name, avail_seat from route natural join train
natural join train_stat where from_st = (select station_id from station
where station_name = 'Kolkata') and to_st = (select station_id from
station where station_name = 'Delhi');

23. Ticket Id and train_id of passengers whose name starts with P:


A. SQL> select Train_id, Ticket_id, P_name from passenger, ticket
where passenger.pnr = ticket.pnr and P_name like 'P%';

19
24. Departure time of trains that leave from Kolkata:
A. SQL> select train_id,depart_time from train natural join route where
from_st = (select station_id from station where station_name = 'Kolkata');

25. Arrival time of trains that reach Delhi:


A. SQL> select train_id,arr_time from train natural join route where to_st
= (select station_id from station where station_name = 'Delhi');

26. Departure dates and times of trains leaving for Delhi from
Kolkata:
A. SQL> select train_id,dept_date, depart_time from train natural join
route where from_st = (select station_id from station where station_name
= 'Kolkata') and to_st = (select station_id from station where
station_name = 'Delhi');

20
27. Arrival time of trains in Delhi order by dates:
A. SQL> select train_id, arr_date, arr_time from route natural join train
where to_st = (select station_id from station where station_name = 'Delhi')
order by arr_date,arr_time;

28. Time and date of the ticket booked by a particular passenger:


A. SQL> select ticket_id,pnr,p_name,train_id, dept_date , depart_time
from (passenger natural join ticket) natural join (train natural join route)
where p_name = 'Prithviraj';

29. Departure and arrival dates and times of all trains registered in
the database:
A. SQL> select train_id,dept_date, depart_time, arr_date, arr_time from
train natural join route order by dept_date;

21
30. Generate a ticket with necessary details:
A. SQL> select ticket_id, pnr, p_name, age, gender, train_id, compart_no,
seat_no, to_st, from_st, dept_date, depart_time, price from (passenger
natural join ticket) natural join (train natural join route) where p_name =
'Prithviraj';

22
Relational Model:

Passenger Ticket
User Pnr Ticket_id

P_name Pnr
U-id
Price
Age
Password
Gender

Seat_no

Reserve_stat

U_id

Train_id

Compart_no

Train
Train_stat
Train_id
Tstatus_id
T_name
Wait_seat
Car_no
Avail_seat
Dept_date
Booked_seat
Arr_date
Train_id

Route Station
Route_id Station_id
From_st
To_st Station_name

Depart_time
Arr_time
No_of_stops
Train_id

23
Future scope of the Project :

Railway system is a huge implementation of databases and as time


advances new procedures of implementing reservation of railway seats
are coming up. Thus, new GUI’s are being developed making it more and
more user friendly. If this database is used in making a GUI with or
online application using Java Server Pages, this can be devised to be a
succesful implementation.

24
Conclusion:
Database Management and Data Handling is a big part of the IT industry.
Thus proper knowledge of SQL is important while working on databases
in order to avoid data redundancy and conflicts. Through this project, we
learned to avoid such data conflicts and implement the queries properly.

25
REMARKS:

26

You might also like