16
Section 08 (a) ER Modelling In Practice 1 HSQ - DATABASES & SQL And Franchise Colleges 08 (a) ER Modelling In Practice QUICKHIRE Car Company

Section 08 (a)ER Modelling In Practice1 HSQ - DATABASES & SQL And Franchise Colleges 08 (a) ER Modelling In Practice QUICKHIRE Car Company

Embed Size (px)

Citation preview

Page 1: Section 08 (a)ER Modelling In Practice1 HSQ - DATABASES & SQL And Franchise Colleges 08 (a) ER Modelling In Practice QUICKHIRE Car Company

Section 08 (a) ER Modelling In Practice 1

HSQ - DATABASES & SQL

And Franchise Colleges

08 (a) ER Modelling In PracticeQUICKHIRE Car Company

Page 2: Section 08 (a)ER Modelling In Practice1 HSQ - DATABASES & SQL And Franchise Colleges 08 (a) ER Modelling In Practice QUICKHIRE Car Company

Section 08 (a) ER Modelling In Practice 2

Case Study : QUICKHIRE Car Company• A nationwide car hire company with depots and hirepoints in all major towns. The depots,

where cars are held, are distinct from the hirepoints where the customer hires their car. One hirepoint has access to several depots and each depot may supply cars to many hirepoints.

• A unique employee number, name, address and telephone number. If the employee works at hirepoints a list of those hirepoints at which the employee may work should be available. Employees work either at hirepoints or at depots. Depot employees do not usually move but hirepoint employees frequently move from one hirepoint to another due to the seasonal nature of the trade. In addition, each hirepoint employee has a known set of hirepoints where they may be used (within travelling distance).

• Depot number, location, number of employees, a list of employees at the depot and a detailed list of cars currently held at each depot. The cars are identified by a unique number and should also have details of registration number, car type, colour, year of manufacture, number of miles travelled, date of last service, miles at last service.

• Hirepoints need a unique hirepoint number, name and location, a list of employees currently working at the hirepoints and a list of the depots a hirepoint may use. Each hiring is assigned a unique number and requires details of customer name, customer address and car numbers. A note is kept of the employee who did the hiring, date hired, and return date.

• Since a customer may be a company rather than an individual, provision is made for the possibility of more than one car being hired in an individual hiring. Each customer is assigned a unique number and many customers may have more than one hiring outstanding at the same time.

Page 3: Section 08 (a)ER Modelling In Practice1 HSQ - DATABASES & SQL And Franchise Colleges 08 (a) ER Modelling In Practice QUICKHIRE Car Company

Section 08 (a) ER Modelling In Practice 3

Where to start?

• The basic (simple entities)– Car

– Hirepoint

– Depot

– Employee

– Customer

– Hiring

• Identifiers? Attributes? Definitions

– Try to do these yourself ..

reg#, car type, colour, year, miles_travelled, date _last_service, miles_last_service….. (A physical car not Car_Type)

hp#, address, name … A place where hirings are arranged.

depot#, address … A place where cars are stored / serviced

emp#, name, DOB, ….. (Works at Hirepoint or Depot ..)

cust#, address … A person or company who may hire a car

hiring#, date, ….. A contract to hire a car or cars

Note:

Why not put hp#, cust#, car#, emp# in Hiring (yet)?

Page 4: Section 08 (a)ER Modelling In Practice1 HSQ - DATABASES & SQL And Franchise Colleges 08 (a) ER Modelling In Practice QUICKHIRE Car Company

Section 08 (a) ER Modelling In Practice 4

Where to start? Cont.

• Where is the money? – Which entity is a transaction of some kind - central to the business?

• Hiring !

Hiring Hirepointat

m 1

• What can we link this to easily?

A Hiring is at exactly 1 Hirepoint

A Hirepoint may arrange 0,1,m Hirings• How about Employee, and Customer - try to extend the ERD to include these.

• How about Hirepoint?– You try it.

Page 5: Section 08 (a)ER Modelling In Practice1 HSQ - DATABASES & SQL And Franchise Colleges 08 (a) ER Modelling In Practice QUICKHIRE Car Company

Section 08 (a) ER Modelling In Practice 5

Adding Employee and Customer

• From the scenario: Each hiring is assigned a unique number and requires details of customer name, customer address and car numbers. A note is kept of the employee who did the hiring, date hired, and return date.

Hiring Hirepointat

m 1to

m1Customer

by m

1Employee

• What about cars?– Try to add this bit.

Page 6: Section 08 (a)ER Modelling In Practice1 HSQ - DATABASES & SQL And Franchise Colleges 08 (a) ER Modelling In Practice QUICKHIRE Car Company

Section 08 (a) ER Modelling In Practice 6

Cars ...• Each hiring is assigned a unique number and requires details of customer name, customer

address and car numbers. A note is kept of the employee who did the hiring, date hired, and return date.

• Since a customer may be a company rather than an individual, provision is made for the possibility of more than one car being hired in an individual hiring.

Hiring Carof

m m

• How can you have a Hiring with no Cars?

• Would you allocate Cars immediately to a Hiring booked 3 weeks in advance?

• Could you have cancelled Hirings? Regular Hirings?

Page 7: Section 08 (a)ER Modelling In Practice1 HSQ - DATABASES & SQL And Franchise Colleges 08 (a) ER Modelling In Practice QUICKHIRE Car Company

Section 08 (a) ER Modelling In Practice 7

Decomposing the m:m

• Decompose this yourself ….

Hiring Carof

m m

???

m1Hiring

?

m 1Car

• What is the new entity?? Try Asymmetric Viewing.

• From left to right:– For a Hiring the new entity gives a list of all the Cars in that Hiring.

• From right to left:– For a Car the new entity give a list of all past Hirings it has been in (or any it has

been assigned to in the future).

Page 8: Section 08 (a)ER Modelling In Practice1 HSQ - DATABASES & SQL And Franchise Colleges 08 (a) ER Modelling In Practice QUICKHIRE Car Company

Section 08 (a) ER Modelling In Practice 8

Attributes for the new entity.

• Try to think of some attributes for the new entity (A particular car in a particular hiring).

– What would Quickhire need to record about the car before it is driven away?

Miles_out, miles_in, condition_out, condition_in, fuel_out, fuel_inYou may have others too.

• If you were sitting in one of the ‘things’ recorded by the new entity by the side of the road, what would you call it?

A Hired Car !

???

m1Hiring

?

m 1Car

inm1

Hiring ism 1

CarHired Car

Page 9: Section 08 (a)ER Modelling In Practice1 HSQ - DATABASES & SQL And Franchise Colleges 08 (a) ER Modelling In Practice QUICKHIRE Car Company

Section 08 (a) ER Modelling In Practice 9

A Primary Key for Hired Car

• A reasonable guess for a Primary Key would be [ hiring#, reg# ]

• We need to test this out as in the lecture on complex entities.

• We will use the table type:

hired_car(hiring#, reg#, miles_out, …...)

• Draw a table occurrence with three sensible rows yourself.

inm1

Hiring ism 1

CarHired Car

Page 10: Section 08 (a)ER Modelling In Practice1 HSQ - DATABASES & SQL And Franchise Colleges 08 (a) ER Modelling In Practice QUICKHIRE Car Company

Section 08 (a) ER Modelling In Practice 10

Testing the hiring#, reg# Primary Key

• Now try to enter the first value of the Primary Key [H4, T125TGY] in a new row …. Use whatever you have in your example.

– See if it makes sense to have a different mileage.

hiring# reg# miles_outH4 T125TGY 12,098H7 T125TGY 13,876H9 S876HJP 24,673

hiring# reg# miles_outH4 T125TGY 12,098H7 T125TGY 13,876H9 S876HJP 24,673H4 T125TGY 14,098

• Does this make any sense?– Can a car go out on the same hiring with two different mileages??

• It looks like the Primary Key is probably valid.

Page 11: Section 08 (a)ER Modelling In Practice1 HSQ - DATABASES & SQL And Franchise Colleges 08 (a) ER Modelling In Practice QUICKHIRE Car Company

Section 08 (a) ER Modelling In Practice 11

The ERD so far ...

• Notice we don’t have Depots yet.

• As we already have Employe we will continue with this aspect.

inm1

Hiring Hired Carto m1Customer

bym

1Employee

is

m

1

Car

Hirepoint

at

1

m

Page 12: Section 08 (a)ER Modelling In Practice1 HSQ - DATABASES & SQL And Franchise Colleges 08 (a) ER Modelling In Practice QUICKHIRE Car Company

Section 08 (a) ER Modelling In Practice 12

Employees• A unique employee number, name, address and telephone number. If the employee works at

hirepoints a list of those hirepoints at which the employee may work should be available. Employees work either at hirepoints or at depots. Depot employees do not usually move but hirepoint employees frequently move from one hirepoint to another due to the seasonal nature of the trade. In addition, each hirepoint employee has a known set of hirepoints where they may be used (within travelling distance).

• Try to fill in the degree of association an membership class for the diagram below.

EmployeeCurrently

works at

1 mDepotHirepoint

Works at

1m

• Later we will find that both of these new relationships will require at table.

EmployeeCurrently

works at

DepotHirepoint Works at

Page 13: Section 08 (a)ER Modelling In Practice1 HSQ - DATABASES & SQL And Franchise Colleges 08 (a) ER Modelling In Practice QUICKHIRE Car Company

Section 08 (a) ER Modelling In Practice 13

Hirepoint Employees

• …. hirepoint employees frequently move from one hirepoint to another due to the seasonal nature of the trade. In addition, each hirepoint employee has a known set of hirepoints where they may be used (within travelling distance).

• Try to model this aspect ...

EmployeeCurrently

works at

1 mHirepoint

EmployeeCurrently

works at

1 mHirepoint

may

work at

m m

• Another m:m to decompose - an attribute of the new entity will be distance_from_home.

• Try to decompose this m:m relationship after the lecture and examine its primary key as before.

Page 14: Section 08 (a)ER Modelling In Practice1 HSQ - DATABASES & SQL And Franchise Colleges 08 (a) ER Modelling In Practice QUICKHIRE Car Company

Section 08 (a) ER Modelling In Practice 14

C u s to m e r

H ir in g H i re d _ C a r

C a r

1

m

1 m 1

H ire p o in t D e p o t

E m p lo y e e

E m p lo y e e -

H P -d e p o t a c c e s s

a v a i la b le -fo r -H P

m

1

m

m

1

m

1

m

1

1

m

C urre nt ly -w ork s a t

C urre nt ly - he ld- a t

W ork s at

is

a t o f

a t

T ab le R eq u ired

T ab le R eq u ired

T ab le R eq u ired

m

a t

to

in is

1

m m

1

Re tu rne d - to

m

1

b y

1

m

1

An almost complete ERD - for you to finish

Page 15: Section 08 (a)ER Modelling In Practice1 HSQ - DATABASES & SQL And Franchise Colleges 08 (a) ER Modelling In Practice QUICKHIRE Car Company

Section 08 (a) ER Modelling In Practice 15

Finishing off• After the lecture you need to :

– Determine the Primary key for the decomposition entity Employee_available_for_HP

– Look at the decomposition entity HP_Depot_Access:• Read about the original M:M relationship in the scenario. • Find an attribute for the entity (something similar to the Employee_available_for_HP

would do).• Determine an appropriate primary key.

– Find another relationship between Depot and Hired_Car.

– Work out how the relationship between Car and Depot relates to the scenario.

– In another session, try to draw the whole ERD just from the scenario & memory.• Don’t forget the primary keys of m:m relationships.• You may find you need to sneak a look at a slide sometimes.

Page 16: Section 08 (a)ER Modelling In Practice1 HSQ - DATABASES & SQL And Franchise Colleges 08 (a) ER Modelling In Practice QUICKHIRE Car Company

Section 08 (a) ER Modelling In Practice 16

End of Lecture