0% found this document useful (0 votes)
12 views

Database

database for bus booking system
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Database

database for bus booking system
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 28

Bahir Dar Institute of

Technology
Bahir Dar University
Faculty of Computing
Departments of Software Engineering

COURSE TITLE : ADVANCED DATABASE SYSTEMS

PROGECT TITLE : BUS TICKET BOOKING SYSTEM

Submitted to:- Tsegaw G.


SUBMISSION DATE : 19/08/2016 EC
BAHIR DAR, ETHIOPIA

0|Page
Name of group members id

1. Wendosen getanhe.....................1404092

2. Tekleeyesus munye...................1404492

3. Wubamlak girum .....................1404373

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.

The problem of the existing system


Here are some potential issues that might exist in the traditional bus ticket management
system:

1. Manual Ticketing Process:


 The reliance on manual ticket issuance processes in physical ticket shops can lead
to errors in ticket details, including passenger information, departure times, and
seat allocations.
2. Limited Accessibility:
 Physical ticket shops may have limited operating hours and locations, making it
inconvenient for passengers to purchase tickets, especially during off-hours or in
remote areas.
3. Ticket Availability and Inventory Management:
 Ticket shops may face challenges in managing ticket inventory, leading to
situations where popular routes sell out quickly or insufficient tickets are available
for certain journeys.
4. Inefficient Customer Service:
 Due to manual processes, ticket shop staff may struggle to handle customer
inquiries, leading to delays in providing information about routes, schedules, or
ticket availability.
5. Data Fragmentation and Lack of Analysis:
 Information about ticket sales, passenger demographics, and route performance
may be scattered across multiple sources or maintained manually, making it
difficult to conduct meaningful analysis for business insights and decision-
making.
6. Limited Payment Options:

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.

Objectives of the Project:


The primary objective of this project is to design and implement an advanced bus ticket
management system that seamlessly integrates with the existing infrastructure of bus
ticket shops while leveraging modern database technologies to enhance efficiency,
accuracy, and customer satisfaction.

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:

1. Database Design and Implementation:

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.

Entity-Relationship (ER) Diagrams


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:

Entity-Relationship (ER) Diagrams

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.

 Map ER diagrams to relational database structures.

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.

Second Normal Form (2NF):


 No composite primary keys to break down.

Third Normal Form (3NF):


 Ensure that there are no transitive dependencies

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

 Generate a database schema diagram using tools like MS SQL Server


Management Studio.

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

Email

Addresse

PaymentMethod
PaymentMethodID

paymentMethodName

descriptionText

Implementation:
Create the database and necessary tables, relationships, and constraints.
create database bus
-- Route Table

CREATE TABLE Route (


 RouteID INT PRIMARY KEY,
 DepartureCity VARCHAR(100),
 ArrivalCity VARCHAR(100),
 Distance FLOAT,
 Duration TIME
 );
PaymentMethod Table

 CREATE TABLE PaymentMethod (


 PaymentMethodID INT PRIMARY KEY,
 Name VARCHAR(100),
 Description TEXT
);
 -- Driver Table
 CREATE TABLE Driver (
 DriverID INT PRIMARY KEY,

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.

CREATE VIEW TicketDetails AS SELECT


t.TicketID,
t.DepartureDateTime,
t.Price,
r.DepartureCity AS DepartureCity,
r.ArrivalCity AS ArrivalCity,
b.BusNumber AS BusNumber,
c.Name AS CustomerName,
b.Type AS BusType,
bk.SeatNumber AS SeatNumber,
bk.Status AS BookingStatus
FROM
Ticket t
JOIN
Route r ON t.RouteID = r.RouteID
JOIN
Bus b ON t.BusID = b.BusID
JOIN
Customer c ON t.CustomerID = c.CustomerID
LEFT JOIN
Booking bk ON t.TicketID = bk.TicketID;

a view that displays the total revenue generated from ticket sales for each route, grouped by
route.

CREATE VIEW RouteRevenue AS


SELECT
r.RouteID,
r.DepartureCity,
r.ArrivalCity,
SUM(t.Price) AS TotalRevenue
FROM
Route r
JOIN
Ticket t ON r.RouteID = t.RouteID
JOIN
Booking bk ON t.TicketID = bk.TicketID
WHERE
bk.Status = 'Confirmed'
GROUP BY
r.RouteID,
r.DepartureCity,
r.ArrivalCity;

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:

1. Index on DepartureDateTime in Ticket Table:


 If you often filter tickets based on departure date and time, creating an index on
the DepartureDateTime column in the Ticket table can speed up these queries.
CREATE INDEX IX_Ticket_DepartureDateTime ON Ticket (DepartureDateTime);
Index on the "RouteID" column in the "Ticket" table: This index can improve the
performance of queries that involve filtering or joining tickets based on the route. Since
routes are likely to be frequently queried or joined with tickets, creating an index on the
"RouteID" column can help optimize these operations.
CREATE INDEX IX_Ticket_RouteID ON Ticket (RouteID);

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.

-- Index on the "CustomerID" column in the "Booking" table

3. CREATE INDEX IX_Booking_CustomerID ON Booking (CustomerID);

Populate the tables with sample data.


 -- Populate Route Table
 INSERT INTO Route (RouteID, DepartureCity, ArrivalCity, Distance, Duration)
 VALUES
 (1, 'AA', 'BAHIRDAR', 225.5, '04:00:00'),
 (2, 'BARIRDAR', 'gonder', 382.7, '06:30:00'),
 (3, 'AA', 'gonder', 938.4, '12:45:00');

 -- Populate PaymentMethod Table
 INSERT INTO PaymentMethod (PaymentMethodID, Name, Description)
 VALUES
 (1, 'Credit Card', 'Pay with a credit card.'),
 (2, 'Debit Card', 'Pay with a debit card.'),
 (3, 'Cash', 'Pay with cash at the counter.');

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;

Delete a specific booking by its ID:



 DELETE FROM Booking
 WHERE BookingID = 456;
Delete all bookings associated with a specific ticket:

 DELETE FROM Booking
 WHERE TicketID = 789;

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

 Demonstrate advanced concepts such as:


 Creating Functions, Stored Procedures, and DML triggers to solve problems.

1. Creating Functions, Stored Procedures, and Triggers:


Functions:
Functions are reusable blocks of code that accept parameters, perform an operation,
and return a value. They can be used to encapsulate frequently used logic and simplify
complex querie

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

SET @TotalPrice = @NumSeats * @PricePerSeat;

RETURN @TotalPrice;
END;

DECLARE @NumSeats INT = 3;


DECLARE @PricePerSeat DECIMAL(10, 2) = 50.00;

SELECT dbo.CalculateTotalPrice(@NumSeats, @PricePerSeat) AS TotalPrice;

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:

 BookTicketProcedure: A stored procedure to handle the booking process, which


includes creating a booking record, updating seat availability, and generating a ticket for
the customer.
 CancelBookingProcedure: A stored procedure to cancel a booking, which involves
updating the booking status, releasing the seat, and possibly issuing a refund.
 GenerateTicketProcedure: A stored procedure to generate a ticket for a booking,
which includes retrieving booking details, customer information, and payment method,
and formatting them into a printable ticket.
 CalculateTotalRevenueProcedure: A stored procedure to calculate the total revenue
generated from ticket sales within a specified date range.
 GetCustomerBookingHistoryProcedure: A stored procedure to retrieve the booking
history of a customer, which includes all the tickets purchased by the customer along
with booking details.
 GetAvailableSeatsProcedure: A stored procedure to retrieve a list of available seats for
a specific route and departure date/time.
 UpdateBookingStatusProcedure: A stored procedure to update the status of a
booking, which may include changing the booking status from "Pending" to
"Confirmed" after payment verification.
 GetRouteDetailsProcedure: A stored procedure to retrieve details of a specific route,
including departure city, arrival city, distance, duration, and bus details.
 CalculateDistanceProcedure: A stored procedure to calculate the distance between
two cities based on their geographic coordinates.

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;

o A stored procedure to delete a booking: This procedure will take a booking ID as a


parameter and delete the specified booking from the database
o CREATE PROCEDURE DeleteBooking
o @BookingID INT
o AS
o BEGIN
o DELETE FROM Booking
o WHERE BookingID = @BookingID;

19 | P a g e
o END;

 Implementing database security and authorization.

CREATE LOGIN bus_ticket_user1 WITH PASSWORD = 'a1234';


CREATE LOGIN bus_ticket_user2 WITH PASSWORD = 'b123';
CREATE LOGIN bus_ticket_user3 WITH PASSWORD = 'c123';
CREATE LOGIN bus_ticket_user4 WITH PASSWORD = 'd123';
CREATE USER bus_ticket_user1 FOR LOGIN bus_ticket_user1;
CREATE USER bus_ticket_user2 FOR LOGIN bus_ticket_user2;
CREATE USER bus_ticket_user3 FOR LOGIN bus_ticket_user3;
CREATE USER bus_ticket_user4 FOR LOGIN bus_ticket_user4;
GRANT SELECT ON Schema::dbo TO bus_ticket_user1;
GRANT SELECT ON Schema::dbo TO bus_ticket_user2;
GRANT SELECT ON Schema::dbo TO bus_ticket_user3;
GRANT SELECT ON Schema::dbo TO bus_ticket_user4;
GRANT EXECUTE ON Schema::dbo TO bus_ticket_user1;
GRANT EXECUTE ON Schema::dbo TO bus_ticket_user2;
GRANT EXECUTE ON Schema::dbo TO bus_ticket_user3;
GRANT EXECUTE ON Schema::dbo TO bus_ticket_user4;

 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.

Booking Tickets: When a customer books a ticket, multiple database operations


occur, including inserting a booking record, updating seat availability, and
possibly processing payment. These operations should be part of a transaction to
ensure that either all operations succeed or none of them do.

BEGIN TRANSACTION; -- Begin the transaction

-- Step 1: Insert a new booking record


INSERT INTO Booking (TicketID, CustomerID, SeatNumber, Status)
VALUES (@TicketID, @CustomerID, @SeatNumber, 'Confirmed');

20 | P a g e
-- Step 2: Update seat availability
UPDATE BusSeat
SET IsAvailable = 0
WHERE BusID = @BusID
AND SeatNumber = @SeatNumber;

-- Step 3: Process payment (if applicable)


-- (Add your payment processing logic here)

-- Commit the transaction if all operations are successful


COMMIT TRANSACTION;

-- Rollback the transaction if any operation fails


-- (SQL S
backup plan.

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.

We work establish our backup based on the following principles

 Frequency of Backups: Perform a full backup of the database once a day.


 Storage Location: Store the backups in a designated folder on the local disk of
the server hosting the SQL Server instance.
 Retention Policy: Retain the backups for one week before overwriting them with
new backups
 USE msdb;
 GO
 EXEC sp_add_job
 @job_name = 'DailyBackupJob';
 GO
 EXEC sp_add_jobstep
 @job_name = 'DailyBackupJob',
 @step_name = 'BackupDatabase',
 @subsystem = 'TSQL',
 @command = 'BACKUP DATABASE [bus_ticket_management] TO DISK = ''C:\document\
database.bak''',
 @on_success_action = 1; -- Quit with success
 GO
 EXEC sp_add_schedule
 @schedule_name = 'DailyBackupSchedule',
 @freq_type = 4, -- Daily
 @freq_interval = 1, -- Every day
 @active_start_time = 000000;
 GO
 EXEC sp_attach_schedule
 @job_name = 'DailyBackupJob',
 @schedule_name = 'DailyBackupSchedule';

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:

1. Enable Publishing on the Publisher Database:

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:

1. Enable Publishing on the Publisher Database:


--Enable Publishing on the Publisher Database:
USE master;
GO
EXEC sp_replicationdboption 'bus', 'publish', TRUE;
GO
GO
2. Add Articles to the Publication
USE bus_ticket_management;
GO
EXEC sp_addarticle @publication = 'BusTicketManagementPublication',
@article = 'customer',
@source_owner = 'dbo',
@source_object = 'customer',
@type = 'logbased',
@schema_option = 0x80030F3; -- Set appropriate schema options
-- Repeat for other tables as needed
GO
3. Add Articles to the Publication
-- Add Articles to the Publication
USE bus_ticket_management;
GO
EXEC sp_addarticle @publication = 'BusTicketManagementPublication',
@article = 'Table1',
@source_owner = 'dbo',
@source_object = 'Table1',

23 | P a g e
@type = 'logbased',
@schema_option = 0x80030F3; -- Set appropriate schema options
-- Repeat for other tables as needed
GO

Streamlined Bus Ticket Booking System: Effortless Management from


Login to Booking
Our platform offers a seamless user experience with a range of features to simplify your journey
planning. With secure login credentials, users can access personalized dashboards where they
can effortlessly manage bookings, explore available routes, and even track their favorite drivers.
Our intuitive interface allows for easy navigation between managing drivers, creating new
routes, and booking tickets with just a few clicks. Whether you're a traveler seeking convenient
bookings or an administrator streamlining operations, our platform ensures a hassle-free
experience from start to finish.

LOGIN PAGE

24 | P a g e
DASHBOARD PAGE

AVAILABLE BUS PAGE

25 | P a g e
CUSTOMERS PAGE

DRIVERS PAGE

26 | P a g e
ROUTES

BOOKING TICKET PAGE

27 | P a g e

You might also like