Taxi Service
Taxi Service
DATABASE SYSTEM
FOR TAXI SERVICE
Table of Contents
REQUIREMENTS .........................................................................................................................
2 MODELLING OF REQUIREMENTS AS ER-
DIAGRAM .................................................................... 3
ASSUMPTIONS: .................................................................................................................................. 3
MAPPING OF ERD IN RELATIONAL SCHEMA .............................................................................. 4
SQL STATEMENS FOR TABLE CREATION .....................................................................................
7
SQL STATEMENS FOR FORIGN KEY CREATION............................................................................ 9
SQL STATEMENS FOR INSERT COMMANDS.............................................................................. 10
PL/SQL – PROCEDURES ............................................................................................................
11
Procedure Code block for Book_Taxi................................................................................................ 11
Procedure Code block for TRIP_END ................................................................................................ 13
PL/SQL – TRIGGERS ..................................................................................................................
15
Procedure Code block for Update_Driver_Rating............................................................................. 15
Procedure Code block for Add_no_of_cars ...................................................................................... 16
NORMALIZATION OF RELATIONAL SCHEMA ............................................................................ 17
1
TAXI SERVICE SYSTEM
REQUIREMENTS
The Taxi Service Database involves around three main entities Taxi, User and Trip.
Taxi can be booked for a specific location with a specific address by a User. User has a
unique User_id, a Contact_no and an Email.
A Taxi Service has a number of taxis for service. Each taxi is described by Taxi_id,
Registration_no, Model, Manufactured year and Status.
Taxi has a parameter Taxi_type. It can be ‘Economy’, ‘Standard’, ’SUV’, ‘Premium’ and
‘Minivan’. Taxi_type defines the price per hour.
A User can reserve a taxi for a number of hours/days. He can use any valid promotional
code.
A user is uniquely identified by his/her User_id. User information consists of his name as
first name, last name, address, age and contact number.
When a user books a taxi and starts the trip by the driver the start time automatically
updated by the system.
When the trip ends, the end trip time also automatically updated in the database by the
system.
A unique bill is generated with a Bill_no after a trip ends which has the information of
user, driver, amount, date.
The total amount and net amount are calculated based on start time, end time, taxi
price per hour and promotional code if any.
A taxi is categorized as Individual Owner and Taxi Service Company. Every taxi has a
owner and he/she can give his/her car for the taxi service. Every owner has SSN and
name. For the taxi service company information like tcs_id and tsc_name will also be
there.
A registered user will be provided with a login id and password. A customer can save his
credit/debit card details for future payment.
Partial payment can also be made at the time of booking and the balance must be paid
by the user at the end of the trip.
If user is a customer, he/she can pay through saved debit/credit card details
A taxi can be drive by a driver. Driver has uniquely identified by the Driver_id. Other
information consists of name, gender, contact_no, rating and age.
After the trip over a unique trip_id is generated for that particular trip. Along with all
the necessary trip_details such as amount, date etc.
Users can also the give the feedback/rating for the trip they traveled into it. The
feedback can be a message or rating out five for the driver who is giving trip to that
user.
Feedback can be taking by the customer service center representative. They have the
information like emp_id, name and email.
2
TAXI SERVICE SYSTEM
ASSUMPTIONS:
Many drivers can drive many taxis (M:N)
Many owners can give many taxis at a time (M:N)
One customer service representative can take one feedback at a time (1:1)
Single user can have multiple trips details (1:N)
Single user can have multiple bills details (1:N)
Single user can give many feedbacks (1:N)
Single user can ride in one taxi at a time (1:1)
3
TAXI SERVICE SYSTEM
4
TAXI SERVICE SYSTEM
TAXI
Taxi_id Registration_no Taxi_Model Taxi_Year Taxi_typ Status Driver_id
e
Primary Key: Taxi_id
Foreign Keys: Driver_id
USER_TBL
Usr_id F_name L_name Contat_no Gender Address Taxi_id
Primary Key: Usr_id
Foreign Keys: Taxi_id
DRIVER
Driver_id F_name L_name Gender Conatct_no Rating Age
Primary Key: Driver_id
Foreign Keys: NA
TRIP_DETAILS
Trip_id Trip_date Trip_amt Driver_id Usr_id
BILL_DETAILS
Bill_no Bill_date Advance_amt Discount_amt Total_amt Usr_id Trip_id
Primary Key: Bill_no
Foreign Keys: Usr_id, Trip_id
CUSTOMER_SERVICE
Emp_id F_name L_name
Primary Key: Emp_id
Foreign Keys: NA
FEEDBACK
Fbk_id Message Email Emp_id Usr_id Trip_id
Primary Key: Fbk_id
Foreign Keys: Usr_id, Emp_id, Trip_id
5
TAXI SERVICE SYSTEM
OWNER_TAXI
Owner_id Taxi_id
Primary Key: Owner_id, Taxi_id
Foreign Keys: Owner_id, Taxi_id
OWNS
Owner_id No_Cars
Primary Key: Owner_id
Foreign Keys: NA
INDIVIDUAL
Ssn Name Owner_id
Primary Key: Ssn
Foreign Keys: Owner_id
TAXI_SERVICE_COMPANY
Tsc_id Tsc_name Owner_id
Primary Key: Tsc_id
Foreign Keys: Owner_id
6
TAXI SERVICE SYSTEM
-- Table Creation
CREATE TABLE
DRIVER (
Driver_id integer NOT NULL,
F_name VARCHAR(10),
L_name VARCHAR(20),
Gender VARCHAR(10),
Conatct_no VARCHAR(20),
Rating integer,
Age integer,
PRIMARY KEY (Driver_id)
);
CREATE TABLE
TRIP_DETAILS (
Trip_id integer NOT NULL,
Trip_date DATE,
Trip_amt decimal(10,2),
Driver_id integer,
Usr_id integer,
Taxi_id integer,
Strt_time TIMESTAMP,
End_time TIMESTAMP,
PRIMARY KEY (Trip_id)
); 7
TAXI SERVICE SYSTEM
CREATE TABLE
CUSTOMER_SERVICE (
Emp_id integer NOT NULL,
F_name VARCHAR(20),
L_name VARCHAR(20),
PRIMARY KEY (Emp_id)
);
CREATE TABLE
TAXI_SERVICE_COMPANY (
Tsc_id integer NOT NULL,
Tsc_name VARCHAR(20),
Owner_id integer,
PRIMARY KEY (Tsc_id)
); 8
TAXI SERVICE SYSTEM
9
TAXI SERVICE SYSTEM
-- Insert Commands
10
TAXI SERVICE SYSTEM
PL/SQL – PROCEDURES
-- Procedure Creation
-- this procedure creates a use_table entry and creates the trip
and bill_detail for the trip
-- input parameters : Name , Address, Contact, Taxi_Model,
Gender, Advance
12
TAXI SERVICE SYSTEM
-- Procedure Creation
-- this procedure will calculate the final amount for the trip
and update the amount attributes in trip and bill details
-- input parameters : trip_id, discount
END ;
/
13
TAXI SERVICE SYSTEM
14
TAXI SERVICE SYSTEM
PL/SQL – TRIGGERS
-- Trigger Creation
-- this trigger is called when inserted(After) to the feedback
table
-- the trigger will decrease the driver rating by 1 if user feed
back is bad for a driver
15
TAXI SERVICE SYSTEM
-- Trigger Creation
-- this trigger is called before the INSERT OR UPDATE ON OWNS
table
-- the trigger will calculate the number of cars owned by the
owner and updates the no_of_cars columns in the OWNS table
16
TAXI SERVICE SYSTEM
USER
{Usr_id F_name, L_name, Contat_no, Gender, Address, Taxi_id}
DRIVER
{Driver_id F_name, L_name, Gender, Conatct_no, Rating, Age}
TRIP_DETAILS
{Trip_id Trip_date, Trip_amt, Driver_id, Usr_id, Taxi_id, Strt_time, End_time}
BILL_DETAILS
{Bill_no Bill_date, Advance_amt, Discount_amt, Total_amt, Usr_id, Trip_id}
CUSTOMER_SERVICE
{Emp_id F_name, L_name}
FEEDBACK
{Fbk_id Message, Email, Emp_id, Usr_id, Trip_id}
OWNER_TAXI
{Owner_id Taxi_id}
OWNS
{Owner_id No_Cars}
INDIVIDUAL
{Ssn Name, Owner_id}
TAXI_SERVICE_COMPANY
{Tsc_id Tsc_name, Owner_id}
17