Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 19

Data Base Management System

Module – 1, T-3

BATCH No. – 10

221FJ01071 - SURAJ KUMAR SINGH


QUESTION
1. Ride-Sharing System or Carpooling Platform
Objective: The objective of this case study is to design a real-time ride-sharing system. The
system will connect passengers with drivers in real-time, allowing them to request and provide rides efficiently. The real-time ride-
sharing system aims to provide a platform where passengers can request rides and drivers can offer their services. The system will match
passengers with available drivers based on their location, preferences, and availability.
Requirements:
1. The system should support multiple users, including passengers and drivers.
2. Passengers should be able to create accounts, log in, and manage their personal information.
3. Passengers can request a ride by specifying their pick-up location, destination, and preferred ride type (e.g., economy, premium, etc.).
4. Drivers can create accounts, log in, and manage their personal information, including their vehicle details.
5. Drivers should be able to update their availability status (e.g., available, unavailable).
6. The system should have real-time tracking functionality to track the location of drivers and display it to passengers during the ride.
QUESTION
7. The system should calculate and display the estimated fare for each ride, based on factors such as distance, ride type, and any
additional charges.
8. Passengers should be able to rate drivers after completing a ride, and drivers should be able to rate passengers as well.
9. The system should maintain a history of past rides for both passengers and drivers.
10. The system should have an admin panel to manage user accounts, handle complaints, and monitor system performance.
Tasks:
a) Identify Entity sets and design an E-R schema for this application.
b) Specify key attributes of each entity type, attribute type and structural constraints on each
relationship type.
c) Based on the Designed E-R Diagram, design corresponding Schema Diagram
d) Discuss any assumptions you made and justify your E-R design choices.
e) Create the tables & implement Primary keys, Foreign keys for the above scenario.
f) Insert related data into the above created tables accordingly.
a) Entity-Relationship (E-R) Schema Design:

 Entities:
User (Generalization of Passenger and Driver)
Passenger
Driver
Ride
RideType
Rating
b) Specify key attributes of each entity type, attribute type
 Attributes:
User :

UserID (Primary Key)


Username
Password
First Name
Last Name
Email
Phone
Role (Passenger/Driver)
Passenger :
PassengerID (Primary Key, Foreign Key referencing User)
Payment Information (e.g., credit card details)

Driver :

DriverID (Primary Key, Foreign Key referencing User)


Vehicle Type
Vehicle Plate Number
Availability Status (Available/Unavailable)
Ride :

RideID (Primary Key)


PassengerID (Foreign Key referencing Passenger)
DriverID (Foreign Key referencing Driver)
Pickup Location
Destination
Ride Type (e.g., economy, premium)
Ride Status (Requested/Ongoing/Completed)
Fare Amount
 Rating :
RatingID (Primary Key)
RatedUserID (Foreign Key referencing User, either Passenger or Driver)
RatedByUserID (Foreign Key referencing User, either Passenger or Driver)
Rating Value (Numeric value representing the rating)

 Relationship :-
Passenger – has many - Rides.
Driver – has many – Rides.
Ride – has one – Rating.
Ride – has one – Payment.
d) Assumptions and Justifications:

I assume that each ride can have only one passenger and one driver.
A user can be both a passenger and a driver, which is why I used a generalization for
the User entity.
RideType entity is used to categorize different types of rides (e.g., economy,
premium) with varying fare structures.
The Rating entity allows both passengers and drivers to rate each other after a
completed ride.
E-R Diagram
e) Table Creation and Primary/Foreign Keys:
CREATE TABLE User (
UserID INT PRIMARY KEY,
Username VARCHAR(50) NOT NULL,
Password VARCHAR(50) NOT NULL,
Email VARCHAR(100) NOT NULL,
Phone VARCHAR(15) NOT NULL
);
CREATE TABLE Passenger (
PassengerID INT PRIMARY KEY,
UserID INT UNIQUE,
Address VARCHAR(200),
FOREIGN KEY (UserID) REFERENCES User(UserID)
);
CREATE TABLE Driver (
DriverID INT PRIMARY KEY,
UserID INT UNIQUE,
VehicleInfo VARCHAR(100),
AvailabilityStatus BOOLEAN,
FOREIGN KEY (UserID) REFERENCES User(UserID)
);

CREATE TABLE RideType (


RideTypeID INT PRIMARY KEY,
TypeName VARCHAR(50) NOT NULL,
BaseFare DECIMAL(10, 2) NOT NULL
);
CREATE TABLE Ride (
RideID INT PRIMARY KEY,
PassengerID INT,
DriverID INT,
PickupLocation VARCHAR(200) NOT NULL,
Destination VARCHAR(200) NOT NULL,
RideTypeID INT,
EstimatedFare DECIMAL(10, 2),
Status VARCHAR(20) NOT NULL,
FOREIGN KEY (PassengerID) REFERENCES Passenger(PassengerID),
FOREIGN KEY (DriverID) REFERENCES Driver(DriverID),
FOREIGN KEY (RideTypeID) REFERENCES RideType(RideTypeID)
);
CREATE TABLE Rating (
RatingID INT PRIMARY KEY,
RideID INT UNIQUE,
RatedUserID INT,
Stars INT,
Comment TEXT,
FOREIGN KEY (RideID) REFERENCES Ride(RideID),
FOREIGN KEY (RatedUserID) REFERENCES User(UserID)
);
F ) Inserting Sample Data:
-- Insert users
INSERT INTO User (UserID, Username, Password, Email, Phone) VALUES
(1, ‘Suraj1’, ‘Suraj@123', ‘Suraj@example.com', ‘7091259062'),
(2, ‘Raja1', ‘Raja@123', ‘Raja@example.com', ‘8596234986');

-- Insert passengers
INSERT INTO Passenger (PassengerID, UserID, Address) VALUES
(1, Suraj@123, 'Patna, City'),
(2, Raja@123, ' Chapra, Town');

-- Insert drivers
INSERT INTO Driver (DriverID, UserID, VehicleInfo, AvailabilityStatus) VALUES
(1, Suraj@123, 'Car Model AA', TRUE)
(2,Raja@123,’Car Model CC’,TRUE);
-- Insert ride types
INSERT INTO RideType (RideTypeID, TypeName, BaseFare) VALUES
(1, 'Economy', 10.00),
(2, 'Premium', 20.00);

-- Insert rides
INSERT INTO Ride (RideID, PassengerID, DriverID, PickupLocation, Destination, RideTypeID, EstimatedFare, Status) VALUES
(1, 1, 1, ‘Patna', ‘Sonpur', 1, 12.50, 'Completed'),
(2, 2, 1, ‘Parmanandpur', ‘Murthan', 2, 25.00, 'Ongoing');

-- Insert ratings
INSERT INTO Rating (RatingID, RideID, RatedUserID, Stars, Comment) VALUES
(1, 1, 1, 4, 'Good ride'),
(2, 1, 2, 5, 'Excellent driver');
User Table
UserID Username Password Email Phone
1 Suraj1 Suraj@123 Suraj@example.com 123-456-7890
2 Raja1 Raja@123 Raja@example.com 987-654-3210

Passenger Table

PassengerID UserID Address


1 Suraj1 Patna-City
2 Raja1 Chapra Town

Driver Table
DriverID UserID VehicleInfo AvailabilityStatus
1 Suraj1 Car Model AA TRUE
2 Raja1 Car Model CC TRUE

17
RideType Table
RideTypeID TypeName BaseFare
1 Economy 10.00
2 Premium 20.00

Ride Table

RideID PassengerID DriverID PickupLocation Destination RideTypeID EstimatedFare Status


1 1 1 Parmanandpur Murthan 1 12.50 Completed
2 2 1 Patna Chapra 2 25.00 Ongoing

Rating Table
RatingID RideID RatedUserID Stars Comment
1 1 1 4 Good ride
2 1 2 5 Excellent driver
THANK YOU

You might also like