Flight DB
Flight DB
BSCS 2B
Activity 2
I. Model
Airline ER Diagram
Airplane Table
Flight Table
Passenger Table
Booking Table
III. Views
It views the flight details (flight number, departure location, and destination) along with the total
number of passengers booked for each flight, including flights with no bookings.
It views the flight details (flight number, departure location, destination, departure date, and
departure time), along with the number of available seats for each flight, by calculating the
difference between the airplane's capacity and the number of passengers booked for the flight. The
data is fetched by joining the Flight, Airplane, and Booking tables, grouped by flight details.
It views the flight details (flight number, departure location, destination, departure date,
departure time, arrival date, arrival time), along with the model number and capacity of the
airplane used for each flight. The data is fetched by joining the Flight and Airplane tables based on
the ModelNumber.
It views the passenger details (passenger ID, given names, surname, email address), along with
their booking ID, flight number, departure city, arrival city, departure date, and departure
time for each booking. The data is fetched by joining the Passenger, Booking, and Flight tables
based on their respective relationships.
It views the passenger details (passenger ID, given names, surname, and email address) from the
Passenger table.
This stored function calculates and returns the number of available seats for a given flight by
subtracting the number of booked seats from the flight's total capacity.
This stored function calculates and returns the number of booked passengers for a specific flight by
counting the number of bookings associated with that flight.
V. Stored Procedures
This stored procedure checks if a passenger already exists based on their email address; if not, it
inserts the new passenger, then creates a booking record for the passenger and flight, and finally
returns a message confirming the booking.
This stored procedure checks if a booking exists using the provided booking ID; if the booking
exists, it deletes the booking and returns a confirmation message, otherwise, it returns a message
stating that the booking could not be found or canceled.
VI. Triggers
This trigger checks if a flight is fully booked when a new booking is being made; if the number of
booked seats is equal to or greater than the flight's capacity, it raises an error and prevents the
booking from being processed.
This trigger updates the Passenger table with the most recent GivenNames, Surname, and
EmailAddress when a booking is updated, ensuring that the passenger's information remains current
in the database.
VII. Events
This is an Event that automatically moves completed flights (older than 1 year) from the Flight table
to the ArchivedFlight table and deletes those flights from the Flight table, typically to run at a
scheduled time.
This Event updates the status of flights to "Completed" for those that have already passed their
scheduled arrival time, ensuring that flights that have arrived are marked as completed.