SlideShare a Scribd company logo
CS 6360.002 Database Design:Uber
Team:
Harshita Rastogi (HXR190001)
Shivam Gupta (SXG190040)
Tejas Gupta (TXG180021)
PROJECT DESCRIPTION:
Uber is a ride providing (car-for-hire) company that provides taxi service to the
customers. Unlike regular taxi service, Uber lets you join as a driver with your
personal registered vehicle and one can make money by completing the customer
request.
Uber system design architecture for embedded system
MAPPING EER DIAGRAM TO RELATIONAL SCHEMA
*Primary Key - Bold *Foreign Key - Italics and Underlined
UberUser { UberID, FName, LName, PhNo, Email, Address , DOB }
Customer { CID, CustomerType, PromoCode, PromoDiscount }
FOREIGN KEY (CID) REFERENCES UberUser(UberID)
Driver { DID , SSN, DLNo, DLExpiry }
FOREIGN KEY (DID) REFERENCES UberUser(UberID)
Vehicle {VID, DID, Model, Color , ManufYear, PurDate, Active, Condition , Cpty, InsuranceNo, InsuranceExpiry, LastChecked }
FOREIGN KEY (DID) REFERENCES Driver(DID)
TripRequests { TripID, CID, DID, TripType, PickupLoc, DropoffLoc, Distance, EstFare, TID }
FOREIGN KEY (TID) REFERENCES PaymentMethod(TID)
FOREIGN KEY (CID) REFERENCES Customer(CID)
FOREIGN KEY (DID) REFERENCES Driver(DID)
CompletedTrips { TripID, DriverArrAt, PickupTime, DropOffTime, ActFare, Tip, Surge }
FOREIGN KEY (TripID) REFERENCES TripRequests(TripID)
IncompleteTrips { TripID, BookingTime, CancelTime, Reason }
FOREIGN KEY (TripID) REFERENCES TripRequests(TripID)
PaymentMethod { TID, CardNo, CVV, ExpDate, CardType, BillingAdd }
PersonalPayment { TID , NameOnCard }
FOREIGN KEY (TID) REFERENCES PaymentMethod(TID)
BusinessPayment { TID, CompanyName }
FOREIGN KEY (TID) REFERENCES PaymentMethod(TID)
Rating { TripID , DriverRating, CustomerRating, DriverFeedback, CustomerFeedback }
FOREIGN KEY (TripID) REFERENCES CompletedTrips(TripID)
Shift { DID , LoginTime, LogoutTime }
FOREIGN KEY (DID) REFERENCES Driver(DID)
FUNCTIONAL DEPENDENCIES AND NORMALIZATION
All the tables contain atomic values. There does not exist any partial dependency in the tables. Therefore, the schema is already obeys
1NF and 2NF.
Driver: There exists transitive dependency. FD2 violates 3NF.
Driver { DID , SSN, DLNo, DLExpiry }
FD1: DID---> DLNo
FD2: DLNo---> DLExpiry
So, the new tables are:
Driver{ DID, SSN, DLNo}
DrivingLicenceInfo{ DLNo, DLExpiry}
Customer: There exists transitive dependency. FD2 violates 3NF.
Customer { CID, CustomerType, PromoCode, PromoDiscount }
FD1: CID ---> PromoCode
FD2: PromoCode ---> PromoDiscount
So, the new tables are:
Customer { CID, CustomerType, PromoCode }
Offer { PromoCode, PromoDiscount }
Vehicle: There exists transitive dependency. FD2 violates 3NF.
Vehicle { VID, DID, Model, Color , ManufYear, PurDate, Active, Condition , Cpty, InsuranceNo, InsuranceExpiry, LastChecked }
FD1: VID---> InsuranceNo
FD2: InsuranceNo> InsuranceExpiry
So, the new tables are:
Vehicle{ VID, DID, Model, Color , ManufYear, PurDate, Active, Condition , Cpty, InsuranceNo, LastChecked }
InsuranceInfo{ InsuranceNo, InsuranceExpiry}
PaymentMethod: There exists transitive dependency. FD2 violates 3NF.
PaymentMethod{ TID, CardNo, CVV, ExpDate, CardType, BillingAdd }
FD1: TID ---> CardNo
FD2: CardNo ---> CVV, ExpDate, CardType, BillingAdd
So, the new tables are:
PaymentMethod { TID , CardNo }
CardInfo { CardNo, CVV, ExpDate, CardType, BillingAdd }
CompletedTrips: There exists transitive dependency. FD2 violates 3NF.
CompletedTrips { TripID, DriverArrAt, PickupTime, DropOffTime, ActFare, Tip, Surge }
FD1: TripID ---> PickupTime
FD2: PickupTime ---> Surge
So the new tables are:
CompletedTrips { TripID, DriverArrAt, PickupTime, DropOffTime, ActFare, Tip }
SurgeInfo { PickupTime , Surge }
NORMALIZED RELATIONAL SCHEMA
*Primary Key - Bold
*Foreign Key - Italics and Underlined
UberUSer { UberID, FName, LName, PhNo, Email, Address , DOB}
Customer { CID, CustomerType, PromoCode}
FOREIGN KEY (CID) REFERENCES UberUser(UberID)
Offer { PromoCode, PromoDiscount }
FOREIGN KEY (PromoCode) REFERENCES Customer(PromoCode)
Driver { DID , SSN, DLNo}
FOREIGN KEY (DID) REFERENCES UberUser(UberID)
DrivingLicenceInfo{ DLNo, DLExpiry}
FOREIGN KEY (DLNo) REFERENCES Driver(DLNo)
Vehicle{ VID, DID, Model, Color , ManufYear, PurDate, Active, Condition , Cpty, InsuranceNo, LastChecked }
FOREIGN KEY (DID) REFERENCES Driver(DID)
InsuranceInfo {InsuranceNo, InsuranceExpiry}
FOREIGN KEY (InsuranceNo) REFERENCES Vehicle(InsuranceNo)
TripRequests { TripID, CID, DID, TripType, PickupLoc, DropoffLoc, Distance, EstFare, TID }
FOREIGN KEY (TID) REFERENCES PaymentMethod(TID)
FOREIGN KEY (CID) REFERENCES Customer(CID)
FOREIGN KEY (DID) REFERENCES Driver(DID)
CompletedTrips { TripID, DriverArrAt, PickupTime, DropOffTime, ActFare, Tip }
FOREIGN KEY (TripID) REFERENCES TripRequests(TripID)
SurgeInfo { PickupTime , Surge }
FOREIGN KEY (PickupTime) REFERENCES CompletedTrips(PickupTime)
IncompleteTrips { TripID, BookingTime, CancelTime, Reason }
FOREIGN KEY (TripID) REFERENCES TripRequests(TripID)
PaymentMethod { TID, CardNo }
CardInfo { CardNo, CVV, ExpDate, CardType, BillingAdd }
FOREIGN KEY (CardNo) REFERENCES PaymentMethod(CardNo)
PersonalPayment { TID , NameOnCard }
FOREIGN KEY (TID) REFERENCES PaymentMethod(TID)
BusinessPayment { TID, CompanyName }
FOREIGN KEY (TID) REFERENCES PaymentMethod(TID)
RATING { TripID , DriverRating, CustomerRating, DriverFeedback, CustomerFeedback }
FOREIGN KEY (TripID) REFERENCES CompletedTrips(TripID)
SHIFT { DID , LoginTime, LogoutTime }
FOREIGN KEY (DID) REFERENCES Driver(DID)
Snapshots of running stored procedures with output and code created on Oracle SQL Developer
Stored Procedure to Calculate Average Ratings of all Drivers:
create or replace PROCEDURE Average_Rating AS
CURSOR DrivRating IS SELECT AVG(R.DriverRating) as AvgRating, T.DID FROM TripRequests T, Rating R WHERE T.TripID=R.TripID GROUP BY T.DID;
thisRating DrivRating%ROWTYPE;
BEGIN
OPEN DrivRating;
LOOP
FETCH DrivRating INTO thisRating;
EXIT WHEN (DrivRating%NOTFOUND);
dbms_output.put_line(thisRating.AvgRating || ' is the Average rating for the driver ID:' || thisRating.DID);
END LOOP;
CLOSE DrivRating;
END;
begin
Average_Rating;
End;
Uber system design architecture for embedded system
2. Stored Procedure to Calculate Total Fare for a given Ride:
create or replace PROCEDURE Calculate_Fare(Base_fare IN number, Service_Tax IN number, Cost_per_mile IN number, Cost_per_min IN number) AS
CURSOR Trip_total_fare IS
SELECT
"A1". "TRIPID" "TRIPID",
"A1"."DURATION" "DURATION",:"A2"."DISTANCE" "DISTANCE",
"A1"."SURGE" "SURGE"
FROM
"TRIPREQUESTS" "A2",
"COMPLETEDTRIPS" "A1"
WHERE
"A2"."TRIPID" = "A1"."TRIPID";
thisTrip Trip_total_fare%rowtype;
thisTotalFare TripRequests.EstFare%TYPE;
BEGIN
OPEN Trip_total_fare;
LOOP
FETCH Trip_total_fare INTO thisTrip;
EXIT WHEN (Trip_total_fare%NOTFOUND);
thisTotalFare:= (Base_fare + Service_Tax + Cost_per_mile*thisTrip.distance + Cost_per_min*thisTrip.duration )*(1 + thisTrip.Surge);
dbms_output.put_line(thisTotalFare || ' is the total fare for the Trip ID:' || thisTrip.TripID);
END LOOP;
CLOSE Trip_total_fare;
END;
Begin
Calculate_Fare(5,10,1,1);
End;
Uber system design architecture for embedded system
Snapshots of running Triggers with errors fired and code on Oracle SQL Developer
1. Trigger to check that the capacity of a vehicle has to be greater than 4:
create or replace TRIGGER Capacity_Check
before update
on Vehicle for each row
Begin
if (:new.cpty < 4) then
raise_application_error( -20001, 'This is a custom error for Capacity');
end if;
End;
Query: update VEHICLE set cpty = 3 where VID= 'V550';
2. Trigger to check that the Driver’s License should not have expired:
create or replace TRIGGER DL_Renewal
before insert or update
on DRIVER for each row
Begin
if (:new.DLEXPIRY < sysdate) then
raise_application_error( -20098, 'This is a custom error for DL EXPIRY');
end if;
End;
Query: Update VEHICLE set INSURANCEEXPIRY = '20-MAY-16' where VID= 'V550';
3. Trigger to check that the Insurance for the vehicle should not have expired:
create or replace TRIGGER Insurance_Renewal
before insert or update
on Vehicle for each row
Begin
if (:new.INSURANCEEXPIRY < sysdate) then
raise_application_error( -20099, 'This is a custom error for Insurance');
end if;
end;
Query: update DRIVER set DLEXPIRY = '20-MAY-16' where DID= 'U233';

More Related Content

PPTX
CARVANA - Predicting the purchase quality in car
ODP
Semantic search in databases
PDF
Predicting model for prices of used cars
PDF
Creating an Uber Clone - Part XXVI - Transcript.pdf
PPTX
Data Warehouse Project
PPTX
Data modelling
PDF
Amadeus Quick Reference Guide
PDF
Entity Relationship Diagram for Fiat Voluntas Tua Travel Reservation Database
CARVANA - Predicting the purchase quality in car
Semantic search in databases
Predicting model for prices of used cars
Creating an Uber Clone - Part XXVI - Transcript.pdf
Data Warehouse Project
Data modelling
Amadeus Quick Reference Guide
Entity Relationship Diagram for Fiat Voluntas Tua Travel Reservation Database

Similar to Uber system design architecture for embedded system (20)

PDF
Amadeus_Guide.pdf
DOCX
DBMS VIVA Report
PDF
Amadeus_Guide from flyingway which guide can help to become a travel agent e...
PPT
Amadeus PPT
PPTX
TRAVEL SPEND OPTIMIZATION FOR POWER SECTOR CPSEs
PDF
Creating an Uber Clone - Part XXVI.pdf
PDF
Report On Travel Cab Agency
PDF
Car Rental Agency - Database - MySQL
PPTX
APPLY ADVANCED AIRFARE RULES AND PROCEDURES
PPT
A Roadmap for Road User Charging
PPTX
Transpotation ERP AppNET Group
PPTX
Publicis Sapient Product Spotlight National Finalist.pptx
PDF
Chapter-4 Introduction to Global Distributions System and Computerized Reserv...
PPTX
Vehicle store and sales management system
PPTX
Long haul trip sheet billing
PDF
GroundOnDemandSalesSheetOct2014
PPTX
Car Rental Systems (ระบบบริหารการเช่ารถยนต์ครบวงจร) by iNT Software.net
PPTX
Lesson 6 Conversion Functions
PPS
Cb driver slide-showpresentation-recruiters
PDF
Creating an Uber Clone - Part XXV - Transcript.pdf
Amadeus_Guide.pdf
DBMS VIVA Report
Amadeus_Guide from flyingway which guide can help to become a travel agent e...
Amadeus PPT
TRAVEL SPEND OPTIMIZATION FOR POWER SECTOR CPSEs
Creating an Uber Clone - Part XXVI.pdf
Report On Travel Cab Agency
Car Rental Agency - Database - MySQL
APPLY ADVANCED AIRFARE RULES AND PROCEDURES
A Roadmap for Road User Charging
Transpotation ERP AppNET Group
Publicis Sapient Product Spotlight National Finalist.pptx
Chapter-4 Introduction to Global Distributions System and Computerized Reserv...
Vehicle store and sales management system
Long haul trip sheet billing
GroundOnDemandSalesSheetOct2014
Car Rental Systems (ระบบบริหารการเช่ารถยนต์ครบวงจร) by iNT Software.net
Lesson 6 Conversion Functions
Cb driver slide-showpresentation-recruiters
Creating an Uber Clone - Part XXV - Transcript.pdf
Ad

Recently uploaded (20)

PPTX
building Planning Overview for step wise design.pptx
PDF
Trusted Executive Protection Services in Ontario — Discreet & Professional.pdf
PPTX
Media And Information Literacy for Grade 12
PPTX
Implications Existing phase plan and its feasibility.pptx
PPTX
Causes of Flooding by Slidesgo sdnl;asnjdl;asj.pptx
PPTX
EDP Competencies-types, process, explanation
PPTX
6- Architecture design complete (1).pptx
PDF
Chalkpiece Annual Report from 2019 To 2025
PPTX
ANATOMY OF ANTERIOR CHAMBER ANGLE AND GONIOSCOPY.pptx
PDF
Phone away, tabs closed: No multitasking
PPTX
An introduction to AI in research and reference management
PPTX
rapid fire quiz in your house is your india.pptx
PPTX
CLASSIFICATION OF YARN- process, explanation
PDF
Integrated-2D-and-3D-Animation-Bridging-Dimensions-for-Impactful-Storytelling...
PDF
Skskkxiixijsjsnwkwkaksixindndndjdjdjsjjssk
PDF
Facade & Landscape Lighting Techniques and Trends.pptx.pdf
PPTX
AC-Unit1.pptx CRYPTOGRAPHIC NNNNFOR ALL
PPT
WHY_R12 Uaafafafpgradeaffafafafaffff.ppt
PPTX
Special finishes, classification and types, explanation
DOCX
actividad 20% informatica microsoft project
building Planning Overview for step wise design.pptx
Trusted Executive Protection Services in Ontario — Discreet & Professional.pdf
Media And Information Literacy for Grade 12
Implications Existing phase plan and its feasibility.pptx
Causes of Flooding by Slidesgo sdnl;asnjdl;asj.pptx
EDP Competencies-types, process, explanation
6- Architecture design complete (1).pptx
Chalkpiece Annual Report from 2019 To 2025
ANATOMY OF ANTERIOR CHAMBER ANGLE AND GONIOSCOPY.pptx
Phone away, tabs closed: No multitasking
An introduction to AI in research and reference management
rapid fire quiz in your house is your india.pptx
CLASSIFICATION OF YARN- process, explanation
Integrated-2D-and-3D-Animation-Bridging-Dimensions-for-Impactful-Storytelling...
Skskkxiixijsjsnwkwkaksixindndndjdjdjsjjssk
Facade & Landscape Lighting Techniques and Trends.pptx.pdf
AC-Unit1.pptx CRYPTOGRAPHIC NNNNFOR ALL
WHY_R12 Uaafafafpgradeaffafafafaffff.ppt
Special finishes, classification and types, explanation
actividad 20% informatica microsoft project
Ad

Uber system design architecture for embedded system

  • 1. CS 6360.002 Database Design:Uber Team: Harshita Rastogi (HXR190001) Shivam Gupta (SXG190040) Tejas Gupta (TXG180021)
  • 2. PROJECT DESCRIPTION: Uber is a ride providing (car-for-hire) company that provides taxi service to the customers. Unlike regular taxi service, Uber lets you join as a driver with your personal registered vehicle and one can make money by completing the customer request.
  • 4. MAPPING EER DIAGRAM TO RELATIONAL SCHEMA *Primary Key - Bold *Foreign Key - Italics and Underlined UberUser { UberID, FName, LName, PhNo, Email, Address , DOB } Customer { CID, CustomerType, PromoCode, PromoDiscount } FOREIGN KEY (CID) REFERENCES UberUser(UberID) Driver { DID , SSN, DLNo, DLExpiry } FOREIGN KEY (DID) REFERENCES UberUser(UberID) Vehicle {VID, DID, Model, Color , ManufYear, PurDate, Active, Condition , Cpty, InsuranceNo, InsuranceExpiry, LastChecked } FOREIGN KEY (DID) REFERENCES Driver(DID) TripRequests { TripID, CID, DID, TripType, PickupLoc, DropoffLoc, Distance, EstFare, TID } FOREIGN KEY (TID) REFERENCES PaymentMethod(TID) FOREIGN KEY (CID) REFERENCES Customer(CID) FOREIGN KEY (DID) REFERENCES Driver(DID)
  • 5. CompletedTrips { TripID, DriverArrAt, PickupTime, DropOffTime, ActFare, Tip, Surge } FOREIGN KEY (TripID) REFERENCES TripRequests(TripID) IncompleteTrips { TripID, BookingTime, CancelTime, Reason } FOREIGN KEY (TripID) REFERENCES TripRequests(TripID) PaymentMethod { TID, CardNo, CVV, ExpDate, CardType, BillingAdd } PersonalPayment { TID , NameOnCard } FOREIGN KEY (TID) REFERENCES PaymentMethod(TID) BusinessPayment { TID, CompanyName } FOREIGN KEY (TID) REFERENCES PaymentMethod(TID) Rating { TripID , DriverRating, CustomerRating, DriverFeedback, CustomerFeedback } FOREIGN KEY (TripID) REFERENCES CompletedTrips(TripID) Shift { DID , LoginTime, LogoutTime } FOREIGN KEY (DID) REFERENCES Driver(DID)
  • 6. FUNCTIONAL DEPENDENCIES AND NORMALIZATION All the tables contain atomic values. There does not exist any partial dependency in the tables. Therefore, the schema is already obeys 1NF and 2NF. Driver: There exists transitive dependency. FD2 violates 3NF. Driver { DID , SSN, DLNo, DLExpiry } FD1: DID---> DLNo FD2: DLNo---> DLExpiry So, the new tables are: Driver{ DID, SSN, DLNo} DrivingLicenceInfo{ DLNo, DLExpiry} Customer: There exists transitive dependency. FD2 violates 3NF. Customer { CID, CustomerType, PromoCode, PromoDiscount } FD1: CID ---> PromoCode FD2: PromoCode ---> PromoDiscount So, the new tables are: Customer { CID, CustomerType, PromoCode } Offer { PromoCode, PromoDiscount }
  • 7. Vehicle: There exists transitive dependency. FD2 violates 3NF. Vehicle { VID, DID, Model, Color , ManufYear, PurDate, Active, Condition , Cpty, InsuranceNo, InsuranceExpiry, LastChecked } FD1: VID---> InsuranceNo FD2: InsuranceNo> InsuranceExpiry So, the new tables are: Vehicle{ VID, DID, Model, Color , ManufYear, PurDate, Active, Condition , Cpty, InsuranceNo, LastChecked } InsuranceInfo{ InsuranceNo, InsuranceExpiry} PaymentMethod: There exists transitive dependency. FD2 violates 3NF. PaymentMethod{ TID, CardNo, CVV, ExpDate, CardType, BillingAdd } FD1: TID ---> CardNo FD2: CardNo ---> CVV, ExpDate, CardType, BillingAdd So, the new tables are: PaymentMethod { TID , CardNo } CardInfo { CardNo, CVV, ExpDate, CardType, BillingAdd } CompletedTrips: There exists transitive dependency. FD2 violates 3NF. CompletedTrips { TripID, DriverArrAt, PickupTime, DropOffTime, ActFare, Tip, Surge } FD1: TripID ---> PickupTime FD2: PickupTime ---> Surge So the new tables are: CompletedTrips { TripID, DriverArrAt, PickupTime, DropOffTime, ActFare, Tip } SurgeInfo { PickupTime , Surge }
  • 8. NORMALIZED RELATIONAL SCHEMA *Primary Key - Bold *Foreign Key - Italics and Underlined UberUSer { UberID, FName, LName, PhNo, Email, Address , DOB} Customer { CID, CustomerType, PromoCode} FOREIGN KEY (CID) REFERENCES UberUser(UberID) Offer { PromoCode, PromoDiscount } FOREIGN KEY (PromoCode) REFERENCES Customer(PromoCode) Driver { DID , SSN, DLNo} FOREIGN KEY (DID) REFERENCES UberUser(UberID) DrivingLicenceInfo{ DLNo, DLExpiry} FOREIGN KEY (DLNo) REFERENCES Driver(DLNo) Vehicle{ VID, DID, Model, Color , ManufYear, PurDate, Active, Condition , Cpty, InsuranceNo, LastChecked } FOREIGN KEY (DID) REFERENCES Driver(DID) InsuranceInfo {InsuranceNo, InsuranceExpiry} FOREIGN KEY (InsuranceNo) REFERENCES Vehicle(InsuranceNo) TripRequests { TripID, CID, DID, TripType, PickupLoc, DropoffLoc, Distance, EstFare, TID } FOREIGN KEY (TID) REFERENCES PaymentMethod(TID) FOREIGN KEY (CID) REFERENCES Customer(CID) FOREIGN KEY (DID) REFERENCES Driver(DID)
  • 9. CompletedTrips { TripID, DriverArrAt, PickupTime, DropOffTime, ActFare, Tip } FOREIGN KEY (TripID) REFERENCES TripRequests(TripID) SurgeInfo { PickupTime , Surge } FOREIGN KEY (PickupTime) REFERENCES CompletedTrips(PickupTime) IncompleteTrips { TripID, BookingTime, CancelTime, Reason } FOREIGN KEY (TripID) REFERENCES TripRequests(TripID) PaymentMethod { TID, CardNo } CardInfo { CardNo, CVV, ExpDate, CardType, BillingAdd } FOREIGN KEY (CardNo) REFERENCES PaymentMethod(CardNo) PersonalPayment { TID , NameOnCard } FOREIGN KEY (TID) REFERENCES PaymentMethod(TID) BusinessPayment { TID, CompanyName } FOREIGN KEY (TID) REFERENCES PaymentMethod(TID) RATING { TripID , DriverRating, CustomerRating, DriverFeedback, CustomerFeedback } FOREIGN KEY (TripID) REFERENCES CompletedTrips(TripID) SHIFT { DID , LoginTime, LogoutTime } FOREIGN KEY (DID) REFERENCES Driver(DID)
  • 10. Snapshots of running stored procedures with output and code created on Oracle SQL Developer Stored Procedure to Calculate Average Ratings of all Drivers: create or replace PROCEDURE Average_Rating AS CURSOR DrivRating IS SELECT AVG(R.DriverRating) as AvgRating, T.DID FROM TripRequests T, Rating R WHERE T.TripID=R.TripID GROUP BY T.DID; thisRating DrivRating%ROWTYPE; BEGIN OPEN DrivRating; LOOP FETCH DrivRating INTO thisRating; EXIT WHEN (DrivRating%NOTFOUND); dbms_output.put_line(thisRating.AvgRating || ' is the Average rating for the driver ID:' || thisRating.DID); END LOOP; CLOSE DrivRating; END; begin Average_Rating; End;
  • 12. 2. Stored Procedure to Calculate Total Fare for a given Ride: create or replace PROCEDURE Calculate_Fare(Base_fare IN number, Service_Tax IN number, Cost_per_mile IN number, Cost_per_min IN number) AS CURSOR Trip_total_fare IS SELECT "A1". "TRIPID" "TRIPID", "A1"."DURATION" "DURATION",:"A2"."DISTANCE" "DISTANCE", "A1"."SURGE" "SURGE" FROM "TRIPREQUESTS" "A2", "COMPLETEDTRIPS" "A1" WHERE "A2"."TRIPID" = "A1"."TRIPID"; thisTrip Trip_total_fare%rowtype; thisTotalFare TripRequests.EstFare%TYPE; BEGIN OPEN Trip_total_fare; LOOP FETCH Trip_total_fare INTO thisTrip; EXIT WHEN (Trip_total_fare%NOTFOUND); thisTotalFare:= (Base_fare + Service_Tax + Cost_per_mile*thisTrip.distance + Cost_per_min*thisTrip.duration )*(1 + thisTrip.Surge); dbms_output.put_line(thisTotalFare || ' is the total fare for the Trip ID:' || thisTrip.TripID); END LOOP; CLOSE Trip_total_fare; END; Begin Calculate_Fare(5,10,1,1); End;
  • 14. Snapshots of running Triggers with errors fired and code on Oracle SQL Developer 1. Trigger to check that the capacity of a vehicle has to be greater than 4: create or replace TRIGGER Capacity_Check before update on Vehicle for each row Begin if (:new.cpty < 4) then raise_application_error( -20001, 'This is a custom error for Capacity'); end if; End; Query: update VEHICLE set cpty = 3 where VID= 'V550';
  • 15. 2. Trigger to check that the Driver’s License should not have expired: create or replace TRIGGER DL_Renewal before insert or update on DRIVER for each row Begin if (:new.DLEXPIRY < sysdate) then raise_application_error( -20098, 'This is a custom error for DL EXPIRY'); end if; End; Query: Update VEHICLE set INSURANCEEXPIRY = '20-MAY-16' where VID= 'V550';
  • 16. 3. Trigger to check that the Insurance for the vehicle should not have expired: create or replace TRIGGER Insurance_Renewal before insert or update on Vehicle for each row Begin if (:new.INSURANCEEXPIRY < sysdate) then raise_application_error( -20099, 'This is a custom error for Insurance'); end if; end; Query: update DRIVER set DLEXPIRY = '20-MAY-16' where DID= 'U233';