Database
Database
Technology
Bahir Dar University
Faculty of Computing
Departments of Software Engineering
0|Page
Name of group members id
1. Wendosen getanhe.....................1404092
2. Tekleeyesus munye...................1404492
4. Temesgen Berhanu...................1405788
5. Yosef Birhanu............................1404237
6. Zelalem Fissha...........................1405490
1|Page
Table of Contents
Introduction.................................................................................................................................................2
The problem of the existing system............................................................................................................3
Objectives of the Project:............................................................................................................................4
Specific Objectives:..................................................................................................................................4
Scope...........................................................................................................................................................4
Entity-Relationship (ER) Diagrams...............................................................................................................5
Entity-Relationship (ER) Diagrams..............................................................................................5
Description..............................................................................................................................................7
Normalization..........................................................................................................................................8
Implementation:........................................................................................................................................10
Views:...............................................................................................................................................11
Indexes:...........................................................................................................................................13
1. Creating Functions, Stored Procedures, and Triggers:............................................................16
Streamlined Bus Ticket Booking System: Effortless Management from Login to Booking.........................24
Introduction
In today's transportation landscape, the convenience of booking bus tickets has become
increasingly vital for both passengers and bus operators. Despite the advent of online
ticketing platforms, many individuals still rely on physical bus ticket shops for their
ticketing needs. These brick-and-mortar establishments serve as essential hubs where
2|Page
passengers purchase tickets, inquire about routes, and seek assistance for their travel
requirements.
The existing bus ticket management system predominantly revolves around these
traditional ticket shops. While they effectively cater to the immediate needs of
customers, there are inherent challenges associated with manual ticketing processes.
These challenges include the potential for errors in ticket issuance, limitations in data
analysis for route optimization, and inefficiencies in inventory management.
3|Page
Traditional ticket shops may only accept cash payments, limiting payment
flexibility for customers who prefer alternative payment methods such as credit
cards or digital wallets.
7. Security Concerns:
With manual record-keeping processes, there may be risks associated with data
security and confidentiality, especially regarding sensitive customer information
such as personal details and payment data.
8. Lack of Integration with Modern Technologies:
The absence of integration with online booking platforms or mobile applications
limits the accessibility and convenience of purchasing tickets for tech-savvy
passengers who prefer digital channels.
Specific Objectives:
1. Develop a comprehensive database system to store and manage bus routes, schedules,
ticket inventory, customer information, and transaction records.
2. Streamline the ticketing process by introducing automated ticket issuance, reservation,
and cancellation functionalities.
3. Implement advanced analytics features to analyze passenger demographics, travel
patterns, and route performance for informed decision-making.
4. Enhance customer experience by providing real-time information on bus availability,
routes, and fare details through user-friendly interfaces.
5. Improve inventory management by optimizing ticket allocation, monitoring ticket sales,
and generating reports on ticket utilization.
Scope
The scope of the project encompasses the following key components:
4|Page
Creation of a robust database schema to store bus routes, schedules, ticket
inventory, customer details, and transaction history.
Implementation of data normalization techniques to ensure data integrity and
efficiency in data retrieval.
2. Ticketing System Enhancement:
Development of features for automated ticket issuance, reservation, and
cancellation to streamline the ticketing process.
Integration of payment gateways to facilitate secure online transactions for ticket
purchases.
3. Analytics and Reporting:
Implementation of analytics tools to analyze passenger demographics, travel
patterns, and route performance.
Generation of reports and visualizations to provide insights for route
optimization and business decision-making.
4. User Interface Development:
Design and development of user-friendly interfaces for both ticket shop staff and
customers, providing access to relevant information and functionalities.
5. Security and Authorization:
Implementation of security measures to protect sensitive customer data and
ensure secure access to the system.
Establishment of role-based access controls to regulate user privileges within the
system.
6. Documentation and Training:
Preparation of comprehensive documentation detailing the system architecture,
functionalities, and usage guidelines.
Provision of training sessions for ticket shop staff on system operation and
maintenance.
the project aims to modernize and optimize the bus ticket management process,
ultimately improving operational efficiency and customer satisfaction.
5|Page
An ER diagram visually represents the entities, attributes, and relationships within a
database system. Here's a suggested structure for your bus ticket management system:
1. Entities:
Bus
Route
Ticket
Customer
Booking
Driver
PaymentMethod
2. Attributes:
Bus:
BusID (Primary Key)
BusNumber
Capacity
Type
DriverID (Foreign Key)
Route:
RouteID (Primary Key)
DepartureCity
ArrivalCity
Distance
Duration
Ticket:
TicketID (Primary Key)
CustomerID (Foreign Key)
RouteID (Foreign Key)
BusID (Foreign Key)
DepartureDateTime
Price
Customer:
CustomerID (Primary Key)
Name
Email
Phone
Address
Booking:
6|Page
BookingID (Primary Key)
TicketID (Foreign Key)
SeatNumber
Status
Driver:
DriverID (Primary Key)
Name
LicenseNumber
ContactInfo
PaymentMethod:
PaymentMethodID (Primary Key)
Name
Description
3. Relationships:
One-to-One: Bus - Driver
One-to-Many: Route - Ticket, Customer - Ticket, Ticket - Booking
Many-to-One: Ticket - Route, Ticket - Customer, Booking - Ticket
Many-to-Many: None in this schema
Description
The Bus entity represents the buses available for booking. Each bus has a unique BusID,
a number, capacity, type, and is associated with a specific driver through the DriverID
foreign key.
The Route entity contains information about the bus routes, including the departure and
arrival cities, distance, and duration of the journey.
The Ticket entity stores information about individual tickets purchased by customers,
including the customer's details, the specific route and bus, departure date and time,
and the ticket price.
The Customer entity represents the passengers purchasing tickets. Each customer has a
unique CustomerID along with their name, email, phone number, and address.
The Booking entity records the bookings made by customers for specific tickets,
including the seat number and booking status.
The Driver entity holds details about the drivers operating the buses, including their
name, license number, and contact information.
The PaymentMethod entity stores information about the various payment methods
available for ticket purchases, including the name and description of each method.
7|Page
BUS table
Bus_ID Bus_no capacty type Driver_I
D
Route table
routID departurcity arrivalcty distance duration
BUS_ROUT table
Bus_ID routID
Ticket table
ticketID departurDateTme price customerID busID routID
Customer table
Customer_ID name email phone address
Booking table
Booking_ID Seat_no status Ticket_ID
Driver table
Driver_ID name License_no Contact_info
Payment_method table
Payment_meethod_ID name discrption
Normalization
First Normal Form (1NF):
All tables already satisfy 1NF as each field contains atomic values.
8|Page
:Because of our tables are already normalized.the normalized tables are:
BUS table
Bus_ID Bus_no capacty type Driver_ID
Route table
Rout_ID Departure_city Arrival_city distance duration
BUS_ROUT table
Bus_ID routID
Tcket table
Ticket_ID Departure_time price Customer_I Bus_ID Rout_I Payment_method_id
D D
Customer table
Customer_ID name email phone address
Booking table
Booking_ID seatno status Ticket_ID
Driver table
Driver_ID name License_no Contact_info
Payment_method table
Payment_meethod_ID name discrption
9|Page
Route bus
Driver
RouteID busID
bus_route DriverID
DepartureCity BusNumber
busID Name
ArrivalCity Capacity
routeID LicenseNumber
Distance bus_type
ContactInfo
Duration DriverID
Booking
BookingID
Ticket
TicketID SeatNumber
DepartureDateTime Status
Price TicketID
RouteID CustomerID
BusID
customerID
PaymentMethodID
Customer
CustomerID
FName
Lname
phone
Addresse
PaymentMethod
PaymentMethodID
paymentMethodName
descriptionText
Implementation:
Create the database and necessary tables, relationships, and constraints.
create database bus
-- Route Table
10 | P a g e
Name VARCHAR(100),
LicenseNumber VARCHAR(50),
ContactInfo VARCHAR(255)
);
CREATE TABLE Bus (
BusID INT PRIMARY KEY,
BusNumber VARCHAR(20),
Capacity INT,
Type VARCHAR(50),
DriverID INT,
FOREIGN KEY (DriverID) REFERENCES Driver(DriverID)
);
create table BUS_ROUT_table(
Bus_ID int, routID int
foreign key(Bus_Id) references bus(BusId),
foreign key(routID) REFERENCES Route(routeID));
-- Customer Table
CREATE TABLE Customer (
CustomerID INT PRIMARY KEY,
Name VARCHAR(100),
Email VARCHAR(100),
Phone VARCHAR(20),
Address VARCHAR(255)
);
-- Ticket Table
CREATE TABLE Ticket (
TicketID INT PRIMARY KEY,
DepartureDateTime DATETIME,
Price DECIMAL(10, 2),
RouteID INT,
BusID INT,
PaymentMethodID INT,
customerID INT,
FOREIGN KEY (RouteID) REFERENCES Route(RouteID),
FOREIGN KEY (BusID) REFERENCES Bus(BusID),
FOREIGN KEY (PaymentMethodID) REFERENCES PaymentMethod(PaymentMethodID),
FOREIGN KEY (customerID) REFERENCES customer(CustomerID)
);
-- Booking Table
CREATE TABLE Booking (
BookingID INT PRIMARY KEY,
TicketID INT,
CustomerID INT,
SeatNumber VARCHAR(10),
Status VARCHAR(20),
FOREIGN KEY (TicketID) REFERENCES Ticket(TicketID),
FOREIGN KEY (CustomerID) REFERENCES Customer(CustomerID)
);
Develop Views and indexes as required.
Views:
11 | P a g e
Views can be used to simplify complex queries, provide a consistent interface to users,
or hide sensitive data. Here are some examples of views you might create for your
system:
a view that provides information about tickets, including details about the route, bus, customer,
and booking status. This view will simplify the retrieval of comprehensive ticket information.
a view that displays the total revenue generated from ticket sales for each route, grouped by
route.
12 | P a g e
These views will provide useful insights into confirmed bookings, available seats, and
revenue generated from ticket sales. You can query these views like tables to retrieve
the desired information.
Indexes:
Indexes can improve the performance of queries by allowing the database engine to
quickly locate rows based on the values of certain columns. Here are some scenarios
where you might create indexes:
2. Index on the "CustomerID" column in the "Booking" table: This index can improve
the performance of queries that involve retrieving bookings for a specific
customer. Since bookings are often associated with customers, creating an index
on the "CustomerID" column can facilitate efficient retrieval of booking
information for individual customers.
13 | P a g e
-- Populate Driver Table
INSERT INTO Driver (DriverID, Name, LicenseNumber, ContactInfo)
VALUES
(1, 'abebe', 'ABC123456', '123-456-7890'),
(2, 'solomon', 'XYZ987654', '456-789-0123');
-- Populate Bus Table
INSERT INTO Bus (BusID, BusNumber, Capacity, Type, DriverID)
VALUES
(1, 'BUS-001', 50, 'Coach', 1),
(2, 'BUS-002', 40, 'Mini Bus', 2);
-- Populate BUS_ROUT_table
INSERT INTO BUS_ROUT_table (Bus_ID, routID)
VALUES
(1, 1), -- Bus 1 serves Route 1
(2, 2); -- Bus 2 serves Route 2
-- Populate Customer Table
INSERT INTO Customer (CustomerID, Name, Email, Phone, Address)
VALUES
(1, 'kebede', '[email protected]', '0987653421', 'AA'),
(2, 'belete', '[email protected]', '0978645321', 'bahirdar');
-- Populate Ticket Table
INSERT INTO Ticket (TicketID, DepartureDateTime, Price, RouteID, BusID,
PaymentMethodID, customerID)
VALUES
(1, '2024-04-15 08:00:00', 50.00, 1, 1, 1, 1),
(2, '2024-04-16 09:00:00', 70.00, 2, 2, 2, 2);
-- Populate Booking Table
INSERT INTO Booking (BookingID, TicketID, CustomerID, SeatNumber, Status)
VALUES
(1, 1, 1, 'A12', 'Confirmed'),
(2, 2, 2, 'B05', 'Confirmed');
Showcase SQL statements for data retrieval, deletion, and updating.
Retrieve all tickets along with their associated route information:
SELECT
t.TicketID,
t.DepartureDateTime,
t.Price,
r.DepartureCity,
r.ArrivalCity
FROM
Ticket t
JOIN
Route r ON t.RouteID = r.RouteID;
14 | P a g e
Retrieve all bookings for a specific customer:
SELECT
b.BookingID,
t.TicketID,
t.DepartureDateTime,
b.SeatNumber
FROM
Booking b
JOIN
Ticket t ON b.TicketID = t.TicketID
WHERE
b.CustomerID = 123;
15 | P a g e
Update the price of a ticket:
UPDATE Ticket
SET Price = 100.00 -- Replace 100.00 with the new price
WHERE TicketID = 789;
Update the status of a booking:
UPDATE Booking
SET Status = 'Cancelled'
WHERE BookingID = 456;
Part B: Advanced
16 | P a g e
Scalar Function: A scalar function returns a single value based on input parameters. We
can create a scalar function that calculates the total price of a booking based on the
number of seats booked and the price per seat.
CREATE FUNCTION CalculateTotalPrice
(
@NumSeats INT,
@PricePerSeat DECIMAL(10, 2)
)
RETURNS DECIMAL(10, 2)
AS
BEGIN
DECLARE @TotalPrice DECIMAL(10, 2);
RETURN @TotalPrice;
END;
Table-Valued Function: A table-valued function returns a table as its result set. We can
create a table-valued function that retrieves all bookings made by a specific customer.
CREATE FUNCTION GetCustomerBookings
(
@CustomerID INT
)
RETURNS TABLE
AS
RETURN
(
SELECT
b.BookingID,
t.TicketID,
t.DepartureDateTime,
b.SeatNumber,
t.Price AS TicketPrice
FROM
Booking b
JOIN
Ticket t ON b.TicketID = t.TicketID
WHERE
b.CustomerID = @CustomerID);
DECLARE @CustomerID INT = 2; -- Replace 123 with the actual customer ID
17 | P a g e
-- Use the function in a SELECT statement
SELECT * FROM dbo.GetCustomerBookings(@CustomerID);Stored Procedures:
Stored procedures are precompiled SQL statements that are stored in the database and
can be executed with parameters. They can perform multiple SQL operations and
provide a way to centralize and manage database logic. Stored procedures can be
implemented in our bus ticket database model to perform various operations efficiently
and securely. Here are some examples of stored procedures that can be useful in our
system:
18 | P a g e
SendBookingConfirmationEmailProcedure: A stored procedure to send a
confirmation email to the customer after a successful booking.
These stored procedures can streamline common tasks and operations in our bus ticket
management system, improve performance, and ensure data consistency and security.
You can customize them according to our specific business requirements and
implement additional procedures as needed.
Let’s create some stored procedures that perform common tasks in the bus ticket
management system. Here are a few ideas:
o A stored procedure to insert a new booking: This procedure will take parameters such as
ticket ID, customer ID, seat number, and status, and insert a new booking into the
database.
o CREATE PROCEDURE InsertBooking
o @TicketID INT,
o @CustomerID INT,
o @SeatNumber VARCHAR(10),
o @Status VARCHAR(20)
o AS
o BEGIN
o INSERT INTO Booking (TicketID, CustomerID, SeatNumber, Status)
o VALUES (@TicketID, @CustomerID, @SeatNumber, @Status);
o END;
o A stored procedure to update the status of a booking: This procedure will take
parameters such as booking ID and new status, and update the status of the specified
booking.
o CREATE PROCEDURE UpdateBookingStatus
o @BookingID INT,
o @NewStatus VARCHAR(20)
o AS
o BEGIN
o UPDATE Booking
o SET Status = @NewStatus
o WHERE BookingID = @BookingID;
o END;
19 | P a g e
o END;
Database transactions.
Implementing database transactions is an essential aspect of database
management, especially in systems where data integrity and consistency are
paramount, such as our bus ticket management system.
Database transactions ensure that a series of database operations are executed
as a single, atomic unit, where either all operations are successfully completed, or
none of them are. This helps maintain data integrity and consistency, even in the
event of system failures or errors during the transaction.
the critical operations in our bus ticket management system that should be executed as
part of transactions.
20 | P a g e
-- Step 2: Update seat availability
UPDATE BusSeat
SET IsAvailable = 0
WHERE BusID = @BusID
AND SeatNumber = @SeatNumber;
A backup plan is crucial for ensuring the safety and integrity of our data. It involves
creating regular backups of the database and its associated components to protect
against data loss due to hardware failures, software errors, or other unforeseen
circumstances.
21 | P a g e
GO
EXEC sp_add_jobserver
@job_name = 'DailyBackupJob',
@server_name = 'DESKTOP-I26EOV5\MSSQLSERVER01';
GO
Designing a distributed database solution and configuring replication
Designing a distributed database solution and configuring replication can
provide fault tolerance, scalability, and improved performance for our bus ticket
management system.
In a distributed database solution, data is distributed across multiple database
servers, allowing for better load balancing and improved availability. Replication
involves copying and synchronizing data between multiple database servers to
ensure consistency and redundancy.
Let's start by configuring transactional replication for our bus ticket management
system. We'll follow these steps:
USE master;
GO
EXEC sp_replicationdboption 'bus', 'publish', TRUE;
GO
Let's start by configuring transactional replication for our bus ticket management
system. We'll follow these steps:
2. Create a Publication
--Create a Publication:
USE bus;
GO
EXEC sp_addpublication @publication = 'BusTicketManagementPublication',
@description = 'Transactional publication of bus ticket management database',
@sync_method = 'concurrent_c',
@retention = 0,
@allow_push = N'true',
@allow_pull = N'true',
@allow_anonymous = N'false';
USE bus_ticket_management;
GO
EXEC sp_addarticle @publication = 'BusTicketManagementPublication',
22 | P a g e
@article = 'customer',
@source_owner = 'dbo',
@source_object = 'customer',
@type = 'logbased',
@schema_option = 0x80030F3; -- Set appropriate schema options
-- Repeat for other tables as needed
GO
1. Identify Publisher and Subscribers: For this assignment, let's assume that our
publisher is the current SQL Server instance where our bus ticket management database
resides, and we'll set up a subscriber on another SQL Server instance.
2. Set Up Distribution Database: We'll configure a distribution database on a separate
server. For simplicity, we'll use the same server as the publisher.
3. Configure Publisher: We'll enable the publisher database for replication and create
publications for the necessary tables.
4. Configure Subscriber: We'll set up a subscription on the subscriber database to
subscribe to the publications created on the publisher.
Let's start by enabling replication on the publisher database and creating publications.
Here are the steps:
23 | P a g e
@type = 'logbased',
@schema_option = 0x80030F3; -- Set appropriate schema options
-- Repeat for other tables as needed
GO
LOGIN PAGE
24 | P a g e
DASHBOARD PAGE
25 | P a g e
CUSTOMERS PAGE
DRIVERS PAGE
26 | P a g e
ROUTES
27 | P a g e