Escolar Documentos
Profissional Documentos
Cultura Documentos
Alana Hill
Alexander J. Singleton
Gabriela Marchiani
Kangkyu Lee
Thomas Lebeau
Our Mission Statement 4
Mission Objectives 4
Requirements 4
Post-Mortem 8
References 10
Appendix 11
Entity Relationship Diagram 11
Relational Database Model 12
Queries 13
Number of Rater Per Location 13
Number of Employee Positions 14
Number of Employee Positions 15
Total Revenue Collected Per State 16
Models Available Within Range 17
Subquery to View Reservation with the Oldest Date 18
Display Customer Reservations with Make and Model of Vehicle 19
Vehicle Maintenance Record Count Completed by Each Employee 20
Total Reservations of Each Rental Office by Sales in Descending Order 21
Total Reservations of Each Rental Office by Sales in Descending Order 22
Employee Information Grouped by Last Name 23
Total Cost of Reservation by Customer ID and Rental Vehicle VIN# 24
Maintenance Log Ordered by Date 25
Reservation Date and Cost According to Rental Office Location 26
Cost of Each Accessory According to Descending Order 27
Report Displaying Customer, Reservation and Vehicle Information 28
Prices of Reservations with the Accessory Cost Added 30
Vehicle Age with Model and Make 31
Employee Count by Rental Office 32
Show Vehicles with Maintenance Records 33
Reservation Count by Office Location 34
Customer Accessory Selection 35
Number of Rental Days 37
1
Singleton, Alexander J., and Shaulinator via Database Admininstrators StackExchange
2
Singleton, Alexander J., and Shaulinator via Database Admininstrators StackExchange
3
Singleton, Alexander J., and Shaulinator via Database Admininstrators StackExchange
4
Singleton, Alexander J., and Shaulinator via Database Admininstrators StackExchange
e. Everytimeacustomerreservesacar,thereservationwillbeassigneda
unique-identifier(ID),Pick-upDate,ReturnDate,DailyRate,Total,
CustomerIDandRentalOfficeID.
f. Acustomercanreservemanycars,butmusthaveatleastonerental
reservation.
g. Acarmaybereservedbymanycustomers,ornoneatall.
h. Amaintenance-logwillrecordVehicleID,Procedure,Date.
i. Therental-companywillofferaccessoriesforeachcustomer-reservation.
Foreachaccessory,wewillmaintainaunique-identifiercalled
SerialNumber,type,cost,andquantitywhichwillcorrespondto
RentalOfficeID,CustomerID,VehicleIDandReservationID.
j. ARentalOfficeLocationcanhavemanyvehicles,butmusthaveatleast
one.
k. AVehiclemaybeusedbymultipleRentalOfficeLocations,butmusthave
atleastone.
l. AVehiclemayhavemanyreservations,ornoneatall.
m. ARentalOfficeLocationcanhavemanyemployees,butmusthaveat
leastone.
n. AnEmployeecanworkatmultipleRentalOfficeLocations,butmustwork
atatleastone.
o. ARentalOfficeLocationcanhavemultipleReservations,andmayhave
none.
p. AReservationmusthaveoneRentalOfficeLocation.
q. AReservationmusthaveonevehicle.
r. AReservationmayhaveoneormoreaccessories,butmayhavenone.
s. AnAccessorycanbeusedinmultipleReservations,ornoneatall.
t. MaintenancemustbecompletedbyatleastoneEmployee,butcanbe
completedbymultipleemployees
u. Theattributevehicleageiscalculatedbysubtractingvehiclemodelyear
fromthedateofreservation.
4. Entity Relationship Diagram (ERD)
a. AnEmployeemayperformmultiplemaintenanceactivities,ortheymay
notperformany.
b. ARentalOfficeLocationmayhavemultiplecustomers,ornoneatall
c. ACustomermayusemultipleRentalOfficeLocations,butmustuseat
leastone(fiveentitiesandatleastfourbinaryrelationships).Atleastone
oftherelationshipsshouldbemanytomany.Showallattributesofall
entities.
d. WeinvitereviewoftheERDmodeledat[LucidCharts](link).
e. Attribute Modeling
i. Bold-ForeignKey
ii. Underline-PotentialPrimaryKey
iii. Tables
1. Accessory (GPS, etc.)
a. SerialNumber
b. Type
c. Cost
d. Quantity
2. Customer
a. CustomerID
b. CustomerFName
c. CustomerLName
d. CustomerEmail
e. DriversLicenseNumber(U)
f. RewardNumber(O)
3. CustomerPhoneNo
a. CustomerID(FK)
b. CustomerPhoneNo
4. Employee
a. EmployeeID
b. EmployeeFName
c. EmployeeLName
d. Title
e. SSN(U)
5. Employing
a. RentalOfficeID(FK)
b. EmployeeID(FK)
6. Includes
a. SerialNumber(FK)
b. ReservationID(FK)
7. MaintenanceLog
a. EmployeeID(FK)
b. VIN(FK)
c. Date
d. Procedure
8. Rental Office Location
a. RentalOfficeID
b. StreetAddress
c. City
d. State
e. ZipCode
9. Reserves
a. SerialNumber(FK)
b. ReservationID(FK)
10. Reservation
a. ReservationID
b. Date(s)
c. DailyRate
d. Total
e. CustomerID(FK)
f. RentalOfficeID(FK)
11. Vehicle
a. VIN
b. Make
c. Model
d. Year
e. Color
f. LicensePlate(U)
g. Mileage
Post-Mortem
Ourinitialmodelsincludedtworelationsthathadidenticalnames:Reserves.
Thiswasasimpleoversightthatmerelyrequiredustoalterthenameofthe
relationbetweenAccessoryandReservationtoIncludes.
OurinitialdesigncalledforaternaryrelationshipbetweenVehicle,Accessory,
andReservationtables.However,afterdiscussionwedecidedtodividethe
singlerelationoutintotwoseparaterelations,onebetweenVehicleand
Reservationtables,andonebetweenAccessoryandReservationtables.Our
logicbehindthisdecisionisthatitisfullypossibleforareservationtonothave
anyaccessoriesattachedtoit,andbyautomaticallyincludingacolumnforthe
accessoryserialnumberintherelationtablecouldresultinasignificantamount
ofnullvaluesforthatcolumn,whichwouldhaveservedasaforeignkey.In
dividingthetworelationsintoseparatetables,wewereabletoensurethatthere
wouldbenonullforeignkeyvalues.
Theinitialdesignonlyallowedforasinglephonenumbertobeassignedtoeach
customer.However,afterdiscussionitwasdecidedthatthiswouldnotbe
sufficient,asmultiplecontactnumbersarecommon.Tosolveforthis,weadded
anadditionaltablethatislinkedtotheCustomertable,usingCustomerIDasa
foreignkeytoincorporatemultiplephonenumbers.Ourinitialimplementationof
thistablewasincorrectthough,astherewasnoprimarykeyassignedtothe
table.AftertestingtheinitialtableCREATEanddataINSERTstatements,we
discoveredourerrorandestablishedthephonenumbercolumnastheprimary
keycolumn.
Atthestart,wehadmisstatedtherequirementsnecessaryforhowtracking
vehiclemaintenancewouldwork.Wehadincorrectlyassumedaonetomany
relationshipbetweenthevehicleandtheemployee,thusoverlookingtheneed
forarelationaltablethatlinkedthesetwoentities.Oncetherequirementshad
beencorrected,wealsodesignedtheMaintenance_Logtable,thatwouldstore
thenecessary,andrelevantdata,fortrackingmaintenanceupdatesperformed
onthevehiclesinquestion.
OurupdateddesigncalledforacolumnlabelledProcedureinthe
Maintenance_LogTable.Duringourdesignphasethough,wedidnotrealize
thatProcedureisareservedterminSQL,anditwouldnotbepossibleforus
tousethistitleforthecolumn.AftertroubleshootingourCREATEstatement,we
discoveredtheerror,andhadtobacktrackandupdateourdesigntore-name
thiscolumnMaintenance_Procedure.
Ourupdateddesignwasalsolackinganothercriticalpieceofdatainregardsto
theMaintenance_Logtable:theprimarykey.Afterexperiencingsomeissuesin
creatingandpopulatingthetable,werealizedthateachindividualprocedure
wouldneedsitsownuniqueidentifier,andaddedintheMaintenance_ID
column.
IndefiningtherequirementsforourReservationtable,wehadspecifiedthe
needtostoredatathatwouldallowforthecalculationoftotalcostofthe
reservation,anddecidedtodosobytrackingthedatesoftherentalandthe
dailycost.However,inourinitialdesign,thetableonlyhadasinglecolumnfor
reservationdates.Storingthisdatainasinglecolumnwouldnothaveallowed
ustoeasilytrackthetotalnumberofdaysthatthereservationspanned,sowe
hadtoupdatethedatabasetoholdanadditionalcolumn,thusallowingusto
splitthedatesintoaPick_Up_DatecolumnandaReturn_datecolumn.
References
1. Singleton, Alexander J., and Shaulinator. "What is a database mission-statement?" Sql -
What is a database mission-statement? - Database Administrators Stack Exchange:
[https://dba.stackexchange.com/questions/165669/what-is-a-database-mission-statemen
t]. Stack Exchange: Database Administrators, 28 Feb. 2017. Web. 08 Mar. 2017.
Appendix
-- This query will count all records within the Daily_Rate column using the
count-function returning the number of records within the RESERVATION-table
grouped by RentalOfficeID, which will then be displayed as an alias-column,
"Number of rates per location."
-- This query will count all of the employed positions by selecting the
Title Column from the Employee-table using the COUNT method in conjunction
with the DISTINCT method to effectively
-- count all unique last-names then grouping the count of unique last names
corresponding to those employee-positions by Title from the EMPLOYEE-Table
displayed in an alias-table "COUNT OF EMPLOYEES."
mysql>
Number of Employee Positions
SELECT CustomerFName
FROM CUSTOMER
WHERE SOUNDEX(CustomerFName) = SOUNDEX('Zitanna');
-- The query should only display the models within the above range, which
this case should be two different
-- makes and the two corresponding models accordingly: "available make and
models with mileage at least 10,000 miles but less than 20,000 miles."
-- This query uses a subquery to view a reservation with the oldest date.
-- This query will display customer reservations with the make and model
of vehicle using three inner joins.
Display Customer Reservations with Make and Model of Vehicle Terminal Output
-- This query counts the maintenance records that each employee has
completed.
--This query adds the total rervations of each rental office by sales in
descending order. The SUM function, a join, group by and order by are used.
SELECT SUM(RESERVATION.Total) AS
Total_Sales,RENTAL_OFFICE_LOCATION.RentalOfficeID FROM RESERVATION
INNER JOIN RENTAL_OFFICE_LOCATION ON RESERVATION.RentalOfficeID =
RENTAL_OFFICE_LOCATION.RentalOfficeID GROUP BY RESERVATION.RentalOfficeID
ORDER BY SUM(RESERVATION.Total) DESC;
Total Reservations of Each Rental Office by Sales in Descending Order Terminal Output
-- 1.) This query will pull employee information, and group the results by
their last name.
-- 2.) This query will pull vehicle and customer identification information
from existing reservations, and display them in order based on the total
cost of the reservation.
Total Cost of Reservation by Customer ID and Rental Vehicle VIN# Terminal Output
-- 3.) This query will pull all rows from the maintenance log, and will
order them by date from most recent to oldest.
SELECT *
FROM MAINTENANCE_LOG
ORDER BY Maintenance_Date;
mysql> SELECT *
-> FROM MAINTENANCE_LOG
-> ORDER BY Maintenance_Date;
+----------------+------------+------------+------------------+------------
-----------+
| Maintenance_ID | EmployeeID | VIN | Maintenance_Date |
Maintenance_Procedure |
+----------------+------------+------------+------------------+------------
-----------+
| 1 | 9 | 11111AAAAA | 2016-05-08 hange
| Oil C
|
| 2 | 10 | 22222BBBBB | 2016-07-27 | Tire
Replacement |
| 3 | 11 | 33333CCCCC | 2016-11-27 | Annual
Maintenance |
| 4 | 12 | 44444DDDDD | 2017-02-08 | Alignment
Check |
+----------------+------------+------------+------------------+------------
-----------+
4 rows in set (0.06 sec)
Reservation Date and Cost According to Rental Office Location
-- 4.) This query will pull reservation date and cost information, and will
display it organized by office location.
Reservation Date and Cost According to Rental Office Location Terminal Output
-- 5.) This query will list each accessory type and its related cost, and
will organize the data in descending order by said cost.
SELECT
RESERVATION.RentalOfficeID,RENTAL_OFFICE_LOCATION.City,RENTAL_OFFICE_LOCATI
ON.State,COUNT(RESERVATION.RESERVATIONID) AS RESERVATIONCOUNT
FROM RESERVATION,RENTAL_OFFICE_LOCATION,RESERVES
WHERE RESERVATION.RentalOfficeID = RENTAL_OFFICE_LOCATION.RentalOfficeID
AND RESERVATION.ReservationID = RESERVES.ReservationID
GROUP BY RENTAL_OFFICE_LOCATION.RentalOfficeID;
mysql> SELECT
RESERVATION.RentalOfficeID,RENTAL_OFFICE_LOCATION.City,RENTAL_OFFICE_LOCATI
ON.State,COUNT(RESERVATION.RESERVATIONID) AS RESERVATIONCOUNT
-> FROM RESERVATION,RENTAL_OFFICE_LOCATION,RESERVES
-> WHERE RESERVATION.RentalOfficeID =
RENTAL_OFFICE_LOCATION.RentalOfficeID
-> AND RESERVATION.ReservationID = RESERVES.ReservationID
-> GROUP BY RENTAL_OFFICE_LOCATION.RentalOfficeID;
+----------------+------------+-------+------------------+
| RentalOfficeID | City | State | RESERVATIONCOUNT |
+----------------+------------+-------+------------------+
| 1 | Portland | OR | 1 |
| 2 | Gilead | NY | 2 |
| 3 | Estes Park | CO | 2 |
| 4 | Derry | ME | 1 |
+----------------+------------+-------+------------------+
4 rows in set (0.07 sec)
Customer Accessory Selection
Select RESERVATION.ReservationID,CUSTOMER.CustomerID,CUSTOMER.CustomerFName
AS FirstName,CUSTOMER.CustomerLName AS
LastName,RENTAL_OFFICE_LOCATION.City,RENTAL_OFFICE_LOCATION.State,ACCESSORY
.Type,ACCESSORY.QUANTITY
FROM RESERVATION, INCLUDES, ACCESSORY, CUSTOMER, RENTAL_OFFICE_LOCATION
WHERE RESERVATION.ReservationID = INCLUDES.ReservationID AND
INCLUDES.SerialNumber = ACCESSORY.SerialNumber AND
CUSTOMER.CustomerID = RESERVATION.CustomerID AND
RESERVATION.RentalOfficeID = RENTAL_OFFICE_LOCATION.RentalOfficeID
ORDER BY CUSTOMER.CustomerLName;
mysql> Select
RESERVATION.ReservationID,CUSTOMER.CustomerID,CUSTOMER.CustomerFName AS
FirstName,CUSTOMER.CustomerLName AS
LastName,RENTAL_OFFICE_LOCATION.City,RENTAL_OFFICE_LOCATION.State,ACCESSORY
.Type,ACCESSORY.QUANTITY
-> FROM RESERVATION, INCLUDES, ACCESSORY, CUSTOMER,
RENTAL_OFFICE_LOCATION
-> WHERE RESERVATION.ReservationID = INCLUDES.ReservationID AND
-> INCLUDES.SerialNumber = ACCESSORY.SerialNumber AND
-> CUSTOMER.CustomerID = RESERVATION.CustomerID AND
-> RESERVATION.RentalOfficeID = RENTAL_OFFICE_LOCATION.RentalOfficeID
-> ORDER BY CUSTOMER.CustomerLName;
+---------------+------------+-----------+-------------+------------+------
-+----------------+----------+
| ReservationID | CustomerID | FirstName | LastName | City | State
| Type | QUANTITY |
+---------------+------------+-----------+-------------+------------+------
-+----------------+----------+
| 3 | 3 | Barry | Allen | Derry | ME
| Phone Charger | 1 |
| 1 | 1 | John | Constantine | Estes Park | CO
| GPS | 1 |
| 2 | 2 | Hal | Jordan | Portland | OR
| GPS | 1 |
| 4 | 4 | Dinah | Lance | Gilead | NY
| Power Inverter | 1 |
+---------------+------------+-----------+-------------+------------+------
-+----------------+----------+
4 rows in set (0.07 sec)
Number of Rental Days
/*Number of Rental Days*/
SELECT
RESERVATION.ReservationID,VEHICLE.VIN,VEHICLE.MAKE,VEHICLE.MODEL,DATEDIFF(R
ESERVATION.Pick_Up_Date,RESERVATION.Return_Date) AS NumOfRentalDays
FROM RESERVATION,VEHICLE,RESERVES
WHERE RESERVATION.ReservationID = RESERVES.ReservationID
AND RESERVES.VIN = VEHICLE.VIN;
mysql> SELECT
RESERVATION.ReservationID,VEHICLE.VIN,VEHICLE.MAKE,VEHICLE.MODEL,DATEDIFF(R
ESERVATION.Pick_Up_Date,RESERVATION.Return_Date) AS NumOfRentalDays
-> FROM RESERVATION,VEHICLE,RESERVES
-> WHERE RESERVATION.ReservationID = RESERVES.ReservationID
-> AND RESERVES.VIN = VEHICLE.VIN;
+---------------+------------+---------+----------+-----------------+
| ReservationID | VIN | MAKE | MODEL | NumOfRentalDays |
+---------------+------------+---------+----------+-----------------+
| 1 | 11111AAAAA | Honda | Accord | -7 |
| 2 | 22222BBBBB | Hyundai | Veloster | -2 |
| 3 | 33333CCCCC | Chevy | Tahoe | -14 |
| 6 | 33333CCCCC | Chevy | Tahoe | -4 |
| 4 | 44444DDDDD | Audi | A4 | -7 |
| 5 | 55555EEEEE | Dodge | Charger | -5 |
+---------------+------------+---------+----------+-----------------+
6 rows in set (0.06 sec)