BUS RESERVATION SYSTEM
MSPM’S
Deogiri Institute of Engineering and Management Studies Aurangabad
A CA2 Presentation for Advanced Database System On
Presented by –
3762 Urja Dhabarde
3771 Mansi Gaikwad
3773 Nikita Dabhade
Under the guidance of
– prof. Sugandha Nandedkar
o ER Diagram
o Normalization
o SQL queries
o Question
Table
of
Contents
I
3
Normalization is a database design technique which is used to organize the tables in such a manner
that it should reduce redundancy and dependency of data. Normalization is a multi step process. It
creates smaller tables from larger tables.
4 commonly used normal forms are first normal form (1NF), second normal form (2NF), third normal
form (3NF), and Boyce-Codd normal form (BCNF).
OBJECTIVES
To make it feasible to represent any relation in the database.
To free relations from undesirable insertion, update, and deletion anomalies.
Anomalies – Unconventional situation
NORMALIZATION
Unnormalized Data
1st Normal Form (1NF)
• Each table cell should contain a single value.
• Each record needs to be unique.
In our data, we will apply 1NF on the passenger table and Bus&Route_details table as they have multi-
valued attributes.
Important Terminologies
• Super Key : Attribute or set of attributes that uniquely identify each record in the relation.
• Candidate Key : A candidate key is super key whose proper subset is not a super key (minimal super key).
• Prime attribute − Part of the candidate-key.
• Non-prime attribute − Not a part of the prime-key
• Functional dependency (A B) means, for all instances of a particular value of A, there is same value for B.
Here, A is determiner and B is dependent factor.
• TYPES OF FUNCTIONAL DEPENDANCIES
Partial dependency
• If there is some attribute that can be removed from A and the dependency still holds.
• Ex. P_id, p_name -> userid
Transitive dependency
• In a relation, if attribute(s) A->B and B->C, the C is transitively dependent on A via B (provided that A is not
functionally dependent on B or C). Ex., Bus_no -> Route_no
• And Route_no -> Route_name
2nd Normal Form (2NF) remove partial dependencies
• A table is in 2 NF if it is 1 NF and if all non prime attributes are dependent upon prime attributes i.e., no patrial
dependency.
• User (user_id  username, email)
• Passenger (P_id  P_name, P_address, DOB, Gender, User_id)
Contacts (Ph_id, P_id  PhNo)
BusRoute (Route_no, Bus_no  B_name, Capacity, Type, Source, Destination, Distance, Fare, Dept_date, Dept_time)
Reservation (SeatNo, Bus_no  Status, BookingDate, TicketNo, ModeOfPayment)
3rd Normal From (3NF) no transitive dependencies
1) User (user_id  username, email)
2) Passenger (P_id  P_name, P_address, DOB, Gender, User_id)
3) Contacts (Ph_id, P_id  PhNo)
• As Bus_no  Route_no & Route_no  Distance, Break BusRoute relation into two tables as:
4) Bus (Bus_no  B_name, Capacity, Type, Route_no)
5) Route (Route_no  R_name, Source, Destination, Distance, Dept_date, Dept_time, Fare)
Now, we apply 3NF on the Reservation table
As SeatNo  TicketNo & TicketNo  ModeOfPayment,
Break the relation into 2 tables as:
6) Booking (SeatNo  P_id, Bus_no, Status, TicketNo)
7) Ticket (TicketNo  BookingDate, ModeOfPayment)
Boyce-Codd Normal Form (BDNF)
• Boyce-Codd Normal Form (BCNF) is an extension of Third Normal Form on strict terms. It has
additional constraints compared with the general definition of 3NF.
• A relation is in BCNF, if and only if, in every non-trivial FD (X Y) X is a super key.
• X  Y is a FD and X intersection Y = 0, then this is non-trivial FD.
• In case of our data, BCNF normalization cannot be applied.
SQL Queries
MOTO – To list the drivers names with salaries>=12000 and <=15000.
-----------------------------------------------------------------------------------------------------------------------------------------------
SQL>
SELECT d_name, salary
FROM driver
WHERE d_id in (SELECT d_id FROM driver WHERE salary BETWEEN 12000 AND 15000);
MOTO - To check the status of seats in shivneri bus. It display the details of shivneri bus.
----------------------------------------------------------------------------------------------------------------------------------------
SQL>
SELECT booking.seat_no, b_name, status
FROM bus1, booking
WHERE bus1.bus_no = booking.Bus_no AND b_name = 'shivneri’;
---------------------------------------------------------------------------------------------------------------------------------------
MOTO – Display 3 max salaries from the drivers table.
-----------------------------------------------------------------------------------------------------------------------------------------
SQL>
SELECT distinct salary
FROM driver a
WHERE 3>= (SELECT COUNT(distinct salary) FROM driver b WHERE a.salary <= b.salary) ORDER BY a.salary
desc;
---------------------------------------------------------------------------------------------------------------------------------------
MOTO – To find the list of passengers who booked ticket using UPI mode and on which date.
passengers booked ticket using UPI.
------------------------------------------------------------------------------------------------------------------------------------------
SQL>
SELECT passenger.p_name, ticket.booking_date
FROM passenger, ticket
WHERE passenger.p_id = ticket.p_id and ticket.modeOfPay = 'UPI’;
-----------------------------------------------------------------------------------------------------------------------------------------
MOTO – To connect the user table with user_id and p_address in passenger table and find which user
belongs to which city.
------------------------------------------------------------------------------------------------------------------------------------------
SQL>
SELECT u.user_id, username, email, p_id, p_address
FROM UserTable u, passenger p
WHERE u.username=p.p_name AND p_address in (SELECT p_address FROM passenger WHERE user_id in
(1,2,3,4,5,6,7));
----------------------------------------------------------------------------------------------------------------------------------------------
MOTO - Display the count of seat_no having status is not booked.
------------------------------------------------------------------------------------------------------------------------------------
SQL>
SELECT COUNT(seat_no)
FROM booking, bus1
WHERE status!='booked’;
------------------------------------------------------------------------------------------------------------------------------------
MOTO - The goal is display the bus name having same bus number where ticket no is T3.
The bus no is connect with the ticket number which show the bus name based on ticket no.
------------------------------------------------------------------------------------------------------------------------------------
SQL>
SELECT b_name
FROM bus1
WHERE bus_no=(SELECT bus_no FROM booking WHERE ticket_no in('T3’));
-------------------------------------------------------------------------------------------------------------------------------------
MOTO – to find the name of passenger name for P1 and with ticket T1 using union operation
------------------------------------------------------------------------------------------------------------------------------------------
SQL>
SELECT p_name FROM passenger WHERE p_id='P1’
UNION
SELECT ticket_no FROM booking WHERE ticket_no='T1’;
------------------------------------------------------------------------------------------------------------------------------------------
MOTO - display the details of passengers who is having uesrid is greater than 3 and paseenger id is
not equal to P1 and P4
----------------------------------------------------------------------------------------------------------------------------------------
SQL>
SELECT * FROM passenger WHERE user_id>3
INTERSECT
SELECT * FROM passenger WHERE p_id!='P1' AND p_id!='P4';
-----------------------------------------------------------------------------------------------------------------------------------------
MOTO - Return the those passengers who has id>3 and address is delhi.
----------------------------------------------------------------------------------------------------------------------------------------------
SQL>
SELECT * FROM passenger WHERE user_id>3
INTERSECT
SELECT * FROM passenger WHERE p_address='delhi’;
----------------------------------------------------------------------------------------------------------------------------------------------
MOTO - Find out the passengers who is having user id >3 and address is not delhi.
--------------------------------------------------------------------------------------------------------------------------------------------
SQL>
SELECT * FROM passenger WHERE user_id>3
MINUS
SELECT * FROM passenger WHERE p_address='delhi’;
---------------------------------------------------------------------------------------------------------------------------------------------------------
Triggers
Moto –
Trigger 1 – To calculate the total salary of a driver by adding the regular salary with bonus using a ‘after insert’ trigger.
Trigger 2 – To set bonus of every driver to Rs200 using ‘after update’ trigger and update the age of driver by one year.
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Trigger 1 –
CREATE TRIGGER trigg1
AFTER INSERT
ON driver
FOR EACH ROW
BEGIN
UPDATE driver SET total = salary + bonus;
END;
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Trigger 2 –
CREATE TRIGGER trigg2
AFTER UPDATE
ON driver
FOR EACH ROW
BEGIN
UPDATE driver SET bonus=200;
END;
Views
Q) With suitable example define view. Discuss the advantages and disadvantages of view in DBMS.
Thank you!

BUS RESERVATION SYSTEM.pptx

  • 1.
    BUS RESERVATION SYSTEM MSPM’S DeogiriInstitute of Engineering and Management Studies Aurangabad A CA2 Presentation for Advanced Database System On Presented by – 3762 Urja Dhabarde 3771 Mansi Gaikwad 3773 Nikita Dabhade Under the guidance of – prof. Sugandha Nandedkar
  • 2.
    o ER Diagram oNormalization o SQL queries o Question Table of Contents
  • 3.
  • 4.
    Normalization is adatabase design technique which is used to organize the tables in such a manner that it should reduce redundancy and dependency of data. Normalization is a multi step process. It creates smaller tables from larger tables. 4 commonly used normal forms are first normal form (1NF), second normal form (2NF), third normal form (3NF), and Boyce-Codd normal form (BCNF). OBJECTIVES To make it feasible to represent any relation in the database. To free relations from undesirable insertion, update, and deletion anomalies. Anomalies – Unconventional situation NORMALIZATION
  • 5.
  • 6.
    1st Normal Form(1NF) • Each table cell should contain a single value. • Each record needs to be unique. In our data, we will apply 1NF on the passenger table and Bus&Route_details table as they have multi- valued attributes.
  • 7.
    Important Terminologies • SuperKey : Attribute or set of attributes that uniquely identify each record in the relation. • Candidate Key : A candidate key is super key whose proper subset is not a super key (minimal super key). • Prime attribute − Part of the candidate-key. • Non-prime attribute − Not a part of the prime-key • Functional dependency (A B) means, for all instances of a particular value of A, there is same value for B. Here, A is determiner and B is dependent factor. • TYPES OF FUNCTIONAL DEPENDANCIES Partial dependency • If there is some attribute that can be removed from A and the dependency still holds. • Ex. P_id, p_name -> userid Transitive dependency • In a relation, if attribute(s) A->B and B->C, the C is transitively dependent on A via B (provided that A is not functionally dependent on B or C). Ex., Bus_no -> Route_no • And Route_no -> Route_name
  • 8.
    2nd Normal Form(2NF) remove partial dependencies • A table is in 2 NF if it is 1 NF and if all non prime attributes are dependent upon prime attributes i.e., no patrial dependency. • User (user_id  username, email) • Passenger (P_id  P_name, P_address, DOB, Gender, User_id)
  • 9.
    Contacts (Ph_id, P_id PhNo) BusRoute (Route_no, Bus_no  B_name, Capacity, Type, Source, Destination, Distance, Fare, Dept_date, Dept_time)
  • 10.
    Reservation (SeatNo, Bus_no Status, BookingDate, TicketNo, ModeOfPayment)
  • 11.
    3rd Normal From(3NF) no transitive dependencies 1) User (user_id  username, email) 2) Passenger (P_id  P_name, P_address, DOB, Gender, User_id) 3) Contacts (Ph_id, P_id  PhNo) • As Bus_no  Route_no & Route_no  Distance, Break BusRoute relation into two tables as: 4) Bus (Bus_no  B_name, Capacity, Type, Route_no) 5) Route (Route_no  R_name, Source, Destination, Distance, Dept_date, Dept_time, Fare) Now, we apply 3NF on the Reservation table As SeatNo  TicketNo & TicketNo  ModeOfPayment, Break the relation into 2 tables as: 6) Booking (SeatNo  P_id, Bus_no, Status, TicketNo) 7) Ticket (TicketNo  BookingDate, ModeOfPayment)
  • 12.
    Boyce-Codd Normal Form(BDNF) • Boyce-Codd Normal Form (BCNF) is an extension of Third Normal Form on strict terms. It has additional constraints compared with the general definition of 3NF. • A relation is in BCNF, if and only if, in every non-trivial FD (X Y) X is a super key. • X  Y is a FD and X intersection Y = 0, then this is non-trivial FD. • In case of our data, BCNF normalization cannot be applied.
  • 13.
    SQL Queries MOTO –To list the drivers names with salaries>=12000 and <=15000. ----------------------------------------------------------------------------------------------------------------------------------------------- SQL> SELECT d_name, salary FROM driver WHERE d_id in (SELECT d_id FROM driver WHERE salary BETWEEN 12000 AND 15000);
  • 14.
    MOTO - Tocheck the status of seats in shivneri bus. It display the details of shivneri bus. ---------------------------------------------------------------------------------------------------------------------------------------- SQL> SELECT booking.seat_no, b_name, status FROM bus1, booking WHERE bus1.bus_no = booking.Bus_no AND b_name = 'shivneri’; ---------------------------------------------------------------------------------------------------------------------------------------
  • 15.
    MOTO – Display3 max salaries from the drivers table. ----------------------------------------------------------------------------------------------------------------------------------------- SQL> SELECT distinct salary FROM driver a WHERE 3>= (SELECT COUNT(distinct salary) FROM driver b WHERE a.salary <= b.salary) ORDER BY a.salary desc; ---------------------------------------------------------------------------------------------------------------------------------------
  • 16.
    MOTO – Tofind the list of passengers who booked ticket using UPI mode and on which date. passengers booked ticket using UPI. ------------------------------------------------------------------------------------------------------------------------------------------ SQL> SELECT passenger.p_name, ticket.booking_date FROM passenger, ticket WHERE passenger.p_id = ticket.p_id and ticket.modeOfPay = 'UPI’; -----------------------------------------------------------------------------------------------------------------------------------------
  • 17.
    MOTO – Toconnect the user table with user_id and p_address in passenger table and find which user belongs to which city. ------------------------------------------------------------------------------------------------------------------------------------------ SQL> SELECT u.user_id, username, email, p_id, p_address FROM UserTable u, passenger p WHERE u.username=p.p_name AND p_address in (SELECT p_address FROM passenger WHERE user_id in (1,2,3,4,5,6,7)); ----------------------------------------------------------------------------------------------------------------------------------------------
  • 18.
    MOTO - Displaythe count of seat_no having status is not booked. ------------------------------------------------------------------------------------------------------------------------------------ SQL> SELECT COUNT(seat_no) FROM booking, bus1 WHERE status!='booked’; ------------------------------------------------------------------------------------------------------------------------------------
  • 19.
    MOTO - Thegoal is display the bus name having same bus number where ticket no is T3. The bus no is connect with the ticket number which show the bus name based on ticket no. ------------------------------------------------------------------------------------------------------------------------------------ SQL> SELECT b_name FROM bus1 WHERE bus_no=(SELECT bus_no FROM booking WHERE ticket_no in('T3’)); -------------------------------------------------------------------------------------------------------------------------------------
  • 20.
    MOTO – tofind the name of passenger name for P1 and with ticket T1 using union operation ------------------------------------------------------------------------------------------------------------------------------------------ SQL> SELECT p_name FROM passenger WHERE p_id='P1’ UNION SELECT ticket_no FROM booking WHERE ticket_no='T1’; ------------------------------------------------------------------------------------------------------------------------------------------
  • 21.
    MOTO - displaythe details of passengers who is having uesrid is greater than 3 and paseenger id is not equal to P1 and P4 ---------------------------------------------------------------------------------------------------------------------------------------- SQL> SELECT * FROM passenger WHERE user_id>3 INTERSECT SELECT * FROM passenger WHERE p_id!='P1' AND p_id!='P4'; -----------------------------------------------------------------------------------------------------------------------------------------
  • 22.
    MOTO - Returnthe those passengers who has id>3 and address is delhi. ---------------------------------------------------------------------------------------------------------------------------------------------- SQL> SELECT * FROM passenger WHERE user_id>3 INTERSECT SELECT * FROM passenger WHERE p_address='delhi’; ----------------------------------------------------------------------------------------------------------------------------------------------
  • 23.
    MOTO - Findout the passengers who is having user id >3 and address is not delhi. -------------------------------------------------------------------------------------------------------------------------------------------- SQL> SELECT * FROM passenger WHERE user_id>3 MINUS SELECT * FROM passenger WHERE p_address='delhi’; ---------------------------------------------------------------------------------------------------------------------------------------------------------
  • 24.
    Triggers Moto – Trigger 1– To calculate the total salary of a driver by adding the regular salary with bonus using a ‘after insert’ trigger. Trigger 2 – To set bonus of every driver to Rs200 using ‘after update’ trigger and update the age of driver by one year. ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Trigger 1 – CREATE TRIGGER trigg1 AFTER INSERT ON driver FOR EACH ROW BEGIN UPDATE driver SET total = salary + bonus; END; ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Trigger 2 – CREATE TRIGGER trigg2 AFTER UPDATE ON driver FOR EACH ROW BEGIN UPDATE driver SET bonus=200; END;
  • 26.
    Views Q) With suitableexample define view. Discuss the advantages and disadvantages of view in DBMS.
  • 27.