Vous êtes sur la page 1sur 19

CS 352

Database Management Systems


Term Project DESIGN REPORT Car Rental Database System
GroupID 13 Cartal
http://code.google.com/p/cartal/

Murat Nalakan 20800182 m_nalcakan@ug

Utku Can Ycel 20702222 u_yucel@ug

Dilara Tara ahintepe 20802578 sahintepe@ug

28.03.2011
1- Revised ER Diagram..............................................................................................................3 2- FDs , Normalization of Tables and Relations.........................................................................4 3- Functional components.........................................................................................................10 3.1 Use Case Diagram...........................................................................................................10

3.2 Algorithms......................................................................................................................11 4- Graphical user interface and corresponding queries.............................................................11 List possible cars for customer.........................................................................................11 Make a reservation for a specific car in specified dates...................................................11 Show Selected Costumers Details and Past Actions.........................................................14 Confirm a reservation as reserved ....................................................................................14 Add a new branch ............................................................................................................14 Add new car to a branch...................................................................................................15 Sign up for a new customer..............................................................................................16 Delete a car from specific branch.....................................................................................16 List all cars ...........................................................................................................................17 List all staff ......................................................................................................................17 Update car price................................................................................................................18 Add a service check..............................................................................................................18

1- Revised ER Diagram
Revised version of our ER diagram is provided below. It is logical to overview the relations before reaching detailed descriptions of the relations.

Figure 1 Revised ER Diagram

2- FDs , Normalization of Tables and Relations


ADDRESS( addressid INTEGER DEFAULT 0 NOT NULL zipcode INTEGER DEFAULT 0 NOT NULL city CHAR(10) NOT NULL detailedaddress VARCHAR(50) NOT NULL phoneno INTEGER PRIMARY KEY(addressid) ) Functional Dependencies: no Candidate Key: (addressid) Normal Form 3NF PERSON( TCidno INTEGER NOT NULL name CHAR(20) NOT NULL age INTEGER NOT NULL PRIMARYKEY TCidno FOREIGN KEY (addressid) REFERENCES ADDRESS (addressid) ) Functional Dependencies: TCidno TCidno addressid Candidate Key: TCidno Normal Form : 3NF SALESMAN( staffid INTEGER NOT NULL branchid INTEGER TCidno INTEGER name CHAR(20) age INTEGER PRIMARY KEY (staffid) FOREIGN KEY (branchId) REFERENCES BRANCH(id) FOREIGN KEY (TCidno) REFERENCES PERSON(TCidno) FOREIGN KEY (name) REFERENCES PERSON(name) FOREIGN KEY (age) REFERENCES PERSON(age) FOREIGN KEY (addressid) REFERENCES PERSON(addressid) ) Functional Dependencies: staffid name age Candidate Keys: staffid, TCidno Normal Form: 3NF DRIVER( staffid INTEGER NOT NULL, branchid INTEGER, TCidno INTEGER , name CHAR(20), age INTEGER , PRIMARY KEY (staffid), FOREIGN KEY (branchId) REFERENCES BRANCH(id), FOREIGN KEY (TCidno) REFERENCES PERSON(TCidno), 4

FOREIGN KEY (name) REFERENCES PERSON(name), FOREIGN KEY (age) REFERENCES PERSON(age), FOREIGN KEY (addressid) REFERENCES PERSON(addressid) ) Functional Dependencies: staffid name age TCidno name age Candidate Keys: staffid, TCidno Normal Form: 3NF CUSTOMER( customerid INTEGER not null name CHAR(20) age INTEGER TCidno INTEGER PRIMARY KEY (customerid) FOREIGN KEY (name) REFERENCES PERSON(name) FOREIGN KEY (age) REFERENCES PERSON(age) FOREIGN KEY (TCidno) REFERENCES PERSON(TCidno) ) Functional Dependencies: customerid name age TCidno name age Candidate Keys: staffid, TCidno Normal Form: 3NF PAYMENT( payment_id INTEGER DEFAULT 0 payment_type CHAR(5), payment_date DATE remaining_amount INTEGER booking_no INTEGER PRIMARY KEY (payment_id) FOREIGN KEY (booking_no) REFERENCES BOOKING(booking_no) ) Functional Dependencies: payment_id remaining_amount payment_type payment_date payment_id booking_no Candidate Keys: payment_id Normal Form: 3NF BOOKING( booking_no INTEGER NOT NULL auto_id INTEGER DEFAULT 0 payment_id INTEGER DEFAULT 0 booking_status CHAR(5) DEFAULT rsrvd pickup_date DATE, pickup_branch_id INTEGER dropoff _date DATE, dropoff_branch_id INTEGER PRIMARY KEY (booking_no) FOREIGN KEY (payment_id) REFERENCES PAYMENT FOREIGN KEY (pickup_branch_id) REFERENCES BRANCH 5

FOREIGN KEY (dropoff_branch_id) REFERENCES BRANCH ) Functional Dependencies: booking_no auto_id payment_id pickup_ payment_id booking_no Candidate Keys: (booking_no) (auto_id, payment_id) Normal Form: 3NF BRANCH( branchid INTEGER not null, branchname CHAR(50) not null, addressid INTEGER not null, autoid INTEGER, detailed address CHAR(500), PRIMARY KEY (branchid), PRIMARY KEY(branchname), PRIMARY KEY(addressid), FOREIGN KEY(autoid) REFERENCES AUTO(autoid), FOREIGN KEY(detailed address) REFERENCES ADDRESS(detailed address), ) Functional Dependencies: branchid->autoid Candidate Key: branchid Normal Form: 3NF AUTO( modelyear INTEGER, lastbookingno INTEGER, autocolor CHAR(20), brandname CHAR(20), modelname CHAR(30), autoid INTEGER, actiondate CHAR(30), servicedetail CHAR(500), insuranceCompany CHAR(50), branchid INTEGER, PRIMARY KEY(modelyear), PRIMARY KEY(lastbookingno), PRIMARY KEY(autocolor), PRIMARY KEY(brandname), PRIMARY KEY(modelname), PRIMARY KEY(autoid), FOREIGN KEY(actiondate) REFERENCES HISTORY(actiondate), FOREIGN KEY(servicedetail) REFERENCES SERVICECHECK(servicedetail), FOREIGN KEY(insuranceCompany) REFECENCES ISURANCECOMPANY(Insurance Company), FOREIGN KEY(branchid) REFERENCES BRANCH(branchid), ) Functional Dependencies: autoid->branched actiondate InsuranceCompany autoid brandname->servicedetail CandidateKeys: autoid brandname Normal Form: 3NF

HISTORY( autoid INTEGER, actiondate CHAR(30), Serviceno INTEGER, PRIMARY KEY(autoid), PRIMARY KEY(actiondate), FOREIGN KEY(Serviceno) REFERENCES REPAIRJOB (Serviceno), ) Functional Dependencies: autoid->Serviceno Candidate Keys: autoid Normal form: 3NF REPAIRJOB( Serviceno INTEGER, ServiceName CHAR(30), ServiceFee INTEGER, Autoid INTEGER, PRIMARY KEY(Serviceno), PRIMARY KEY(ServiceName), PRIMARY KEY(ServiceFee), FOREIGN KEY(autoid) REFERENCES HISTORY (autoid), ) Functional Dependencies: Serviceno->autoid Candidate Keys: Serviceno Normal Forms: 3NF ACCIDENT( Acdetails CHAT(500), Accplace CHAR(50), Customerid INTEGER, autoid INTEGER, PRIMARY KEY(Accdetails), PRIMARY KEY(Accplace), PRIMARY KEY(Customerid), FOREIGN KEY(autoid) REFERENCES HISTORY(autoid), ) Functional dependencies: Accplace->autoid Candidate Keys: Accplace Normal Forms: 3NF SERVICECHECK( NextCheckDate INTEGER, Serviceid INTEGER, ServiceDetail CHAR(500), Autoid INTEGER, PRIMARY KEY(NextCheckDate), PRIMARY KEY(Serviceid), PRIMARY KEY(ServiceDetail), FOREIGN KEY(autoid) REFERENCES AUTO(autoid), )

Functional Dependencies: Serviceid->autoid Candidate Keys: Serviceid Normal Forms: 3NF INSURANCECOMPANY( InsuranceCompany CHAR(50), Amount INTEGER, Autoid INTEGER, PRIMARY KEY(InsuranceCompany), PRIMARY KEY(Amount), PRIMARY KEY(Autoid), ) Does( customerid(6) not null, payment_id (6) not null, PRIMARY KEY (customerid), FOREIGN KEY (customerid) REFERENCES Customer(), FOREIGN KEY (payment_id) REFERENCES Payment( id), ) Candidate Keys: (customerid payment_id) Normal Form: 3NF Requires( payment_id INTEGER(6) not null, bookingno INTEGER(6) not null, PRIMARY KEY ( payment_id ,bookingno), FOREIGN KEY (payment_id ) REFERENCES Payment(id), FOREIGN KEY (bookingno) REFERENCES Booking(bookingno), ) Candidate Keys: (payment_id bookingno) Normal Form: 3NF Makes(customerid INTEGER(6) not null, bookingno INTEGER(6)not null, PRIMARY KEY(customer id, bookingno), FOREIGN KEY (customerid ) REFERENCES Customer(id), FOREIGN KEY (bookingno ) REFERENCES Booking(bookingid) ) Candidate Keys: (customerid,bookingno) Normal Form: 3NF Confirms ( staffid INTEGER(6)not null, bookingno INTEGER (6) not null, PRIMARY KEY (staffid, bookingno), FOREIGN KEY (staffid) REFERENCES Salesman( id) , FOREIGN KEY (bookingid) REFERENCES Booking(bookingid) ) Candidate Keys: (staffid, bookingno)

Normal Form: 3NF has( staffid INTEGER(6) not null, branchid INTEGER (6) not null, PRIMARY KEY (staffid, branchid) , FOREIGN KEY (staffid) REFERENCES Person(staffid), FOREIGN KEY (branchid) REFERENCES Branch(branchid) ) Candidate Keys: (staffid,branchid) Normal Form: 3NF Stay( staffid INTEGER(6) not null, addressid INTEGER(6) , PRIMARY KEY(staffid), FOREIGN KEY (staffid) REFERENCES Person(staffid), FOREIGN KEY (addressid) REFERENCES Address(addressid), ) Candidate Keys: (staffid) Normal Form: 3NF Located( addressid INTEGER(6), branchid INTEGER(6)not null, PRIMARY KEY(addressid,branchid), FOREIGN KEY (addressid) REFERENCES Address(addressid), FOREIGN KEY (branchid) REFERENCES Branch(branchid), ) Candidate Keys: (addressid) Normal Form : 3NF Works For( staffid INTEGER, branchid INTEGER, PRIMARY KEY(staffid, branchid) ) Candidate KEys: staffid,branchid Normal Form: 3NF Owns( branchid INTEGER, autoid INTEGER, PRIMARY KEY(autoid,branchid), FOREIGN KEY (autoid) REFERENCES AUTO(autoid), FOREIGN KEY (branchid) REFERENCES Branch(branchid), ) Candidate Keys: branchid,autoid Normal Forms: 3NF Has(

autoid INTEGER, PRIMARY KEY(autoid), ) Needs( NextCheckDate INTEGER, Serviceid INTEGER, autoid INTEGER, PRIMARY KEY(autoid, NextCheckDate, Serviceid), ) Candidate Keys: autoid, NextCheckDate, Serviceid Normal Forms: 3NF Insuaredby( ExpirationDate INTEGER, Autoid INTEGER, InsuranceCompany INTEGER, PRIMARY KEY(ExpirationDate), FOREIGN KEY(Autoid) REFERENCES AUTO(autoid), FOREIGN KEY(InsuranceCompany) REFERENCES INSURANCECOMPANY(InsuranceCompany) ) Candidate KEys: Autoid, InsuranceCompanmy Normal Forms: 3NF

3- Functional components
3.1 Use Case Diagram
There will be two types of users in our system. We will only allow Customers and Branch Staffs to use system.

Figure 2 Use Case Diagram

10

3.2 Algorithms
There will be two different algorithms which will be used for update information of discount amount and next service date. Since this algorithm needs input from the previous servicecheck our database will initially select the previous service check of the auto. nextservicecheckdate = previousservicedate + regularcheckperiod

4- Graphical user interface and corresponding queries


List possible cars for customer

inputs( branch_id, car_brand, car_model, pickup_date, dropoff_date, totaldays) SELECT A.modelname A.modelyear A.brandname A.color A.carfare FROM AUTO A BRANCH B BOOKING BOO WHERE A.branch_id = branch_id AND A.brandname = car_brand AND A.modelname = car_model NOT EXIST (SELECT * FROM BOOKING B2 AUTO A2 WHERE B2.autoid = A2.autoid )

Make a reservation for a specific car in specified dates


User is allowed to make reservation for a car in a time period. However, user can not be able to make payment online. Only salesman can accept and confirm a payment. inputs($autoid, $pickup_branchid, $pickup_date, $dropoff_date, )

11

INSERT INTO BOOKING(bookingno, customerid, autoid, paymentno, reservationdate,pickup_date, pickup_branchid,dropoff_date, dropoff_branchid) VALUES ($bookingno, $customerid, $autoid, $paymentno, $reservationdate , $pickup_date, $pickup_branchid, $dropoff_date, $dropoff_branchid) INSERT INTO PAYMENT (payment_id, remaining_amount, booking_no, payment_date, payment_type) VALUES ($payment_id, $remaining_amount, $booking_no, NULL, NULL)

Previous screen sample can only show the possible cars with their daily fares. In order to complete the reservation user should decide the drop off place and then the table will be updated.

12

when customer fulfills a payment, the table will be updated by the salesman

inputs: $payment_type, $payment_amount UPDATE PAYMENT SET payment_type = $payment_type AND remaining_amount =remaining_amount payment_amount 13

WHERE payment_id = $payment_id

Show Selected Costumers Details and Past Actions


SELECT Booking.booking_no P.payment_status P.remaining_amount A.modelname A.modelyear FROM BOOKING Booking PAYMENT P AUTO A WHERE Booking.customerid = $customer_id AND P.paymentno = Booking.paymentno AND Booking.auto_id = A.autoid

Confirm a reservation as reserved


UPDATE BOOKING B SET B.reservationstatus = rsrvd confirm the payment of a reservation UPDATE BOOKING B SET B.reservationstatus = paid

Add a new branch


Inputs: ( $branchid, $branchname, $addressid, $detailedaddress, $phoneno) INSERT

14

INTO ADDRESS(addressid, detailedaddress) VALUES(detailedaddress, addressid, phoneno) INSERT INTO BRANCH (branchid,branchname, addressid) VALUES(branchid, branchname, addressid)

Add new car to a branch


Inputs: (autoid, brandname,modelyear, modelname, autocolor,lastbookingno) INSERT INTO AUTO (autoid, brandname,modelyear, modelname, autocolor,lastbookingno) VALUES (autoid, brandname,modelyear, modelname, autocolor,lastbookingno) $autoid = Last index of Autoid

15

Sign up for a new customer


inputs ($name, $age, $address, $TCid, $address, $city, $detailedaddress, $zipcode, $phoneno) variables $customerid : Last index of customerid INSERT INTO CUSTOMER (customerid, name, age, TCidno) VALUES ($customerid , $name, $age , $TCid) INSERT INTO PERSON(age, name , TCid) VALUES($age ,$name, $TCid) INSERT INTO ADDRESS(addressid, city, detailedaddress, zipcode, phoneno) VALUES($address, $city, $detailedaddress, $zipcode, $phoneno)

Delete a car from specific branch


input: $autoid DELETE FROM AUTOS A WHERE A.autoid = $autoid

16

List all cars

input: $branchid SELECT * FROM AUTO A BRANCH B WHERE B.branchid = A.branchid AND A.branchid = $branchid

List all staff

17

input: $staffid SELECT * FROM PERSON P BRANCH B WHERE B.branchid = A.branchid AND A.branchid = $branchid

Update car price

input: $newvalue UPDATE AUTO A SET A.dailyfare = $newvalue

Add a service check


inputs: $autoid $nextcheckdate = previous check date + regular check period $serviceid SELECT A.autoid FROM AUTO A WHERE A.autoid = $autoid AND SELECT SC.nextcheckdate FROM SERVICECHECK SC SERVICECHECK SC2 WHERE SC.autoid = $autoid AND SC2.serviceid > SC.serviceid

18

INSERT INTO SERVICECHECK(nextcheckdate, serviceid, servicedetail, autoid) VALUES ($nextcheckdate, $serviceid, NULL, $autoid) Finally we will have a simple login screen which separates the users. According to the given credentials, system will differentiate the customers from branch staffs.

19

Vous aimerez peut-être aussi