ER modelling

15
ER modelling Practice

description

ER modelling. Practice. Starter. What are the four degrees of relationship? o ne to one (1:1) one to many (1:n) many to one (n:1) many to many ( n:n ) Is there a problem implementing any of these relationships? many to many relationships have to be broken down. The Chocolate Factory……. - PowerPoint PPT Presentation

Transcript of ER modelling

Page 1: ER modelling

ER modelling

Practice

Page 2: ER modelling

Starter

• What are the four degrees of relationship?– one to one (1:1)– one to many (1:n)– many to one (n:1)– many to many (n:n)

• Is there a problem implementing any of these relationships?– many to many relationships have to be broken

down

Page 3: ER modelling

The Chocolate Factory…….

Wants to store details of all it’s chocolate bars and the ingredients required to make them.

•Write a list of possible Entities and Attributes that could be used in a database•Construct an ER Diagram to represent the relationships involved.

Page 4: ER modelling

Possible Solution

• Entity– Choc Bar

– Ingredient

• Attribute– Name– Price– Weight– Stock level

– Name – Quantity required– Price/Kg– Stock level– Reorder level

Page 5: ER modelling

Possible ER Diagram

CHOC BAR

INGREDIENT

CHOC BAR

INGREDIENT

BAR/INGREDIENT

Choc bar contains many ingredients.

Each ingredient can be included in many choc bars

Need to resolve this many to many relationship

Page 6: ER modelling

The online DVD store……

Wants to store details of it’s DVDs and its customers.The store wants to record which customers buy which DVDs so it can make recommendations

•Write a list of possible Entities and Attributes that could be used in a database•Construct an ER Diagram to represent the relationships involved

Page 7: ER modelling

Possible Solution

• Entity– Customer

– DVD

• Attribute– Name– Address– email– preferred genre

– Name – Duration– Genre– Price

Page 8: ER modelling

possible ER Diagram

Customer

DVD Title

Customer

DVD Title

DVD Copy

Need to resolve this many to many relationship

Customer may purchase many DVDs

Each DVD title can be bought by many customers

Page 9: ER modelling

The Hospital…….

A hospital is organised into wardsEach ward is staffed by one or more nursesEach patient is assigned to a single ward and is under the care of a single consultantA consultant will see many patients

•Write a list of possible Entities and Attributes that could be used in the database•Construct an ER Diagram to represent the relationships involved

Page 10: ER modelling

Possible solution• Entity

– WARD

– NURSE

– PATIENT

– CONSULTANT

• Attribute– Name– Number of beds

– Name – Address

– Name– DOB– Blood group

– Name– Specialism

Page 11: ER modelling

Possible ER Diagram

WARD

PATIENT

NURSE

CONSULTANT

A ward can hold one or more patients and is staffed by one or more nurses

A Consultant will see many Patients

A patient is assigned to one ward and is seen by one consultant

A nurse works on one ward

is staffed by

sees

holds

Page 12: ER modelling

The college…….

A college employs teachers to deliver subjectsEach subject may be chosen by one or more studentsEach student may study up to 4 subjectsA teacher may teach one or more subjects

•Construct an ER Diagram to represent the relationships involved

Page 13: ER modelling

Possible ER Diagram

STUDENT SUBJECT

TEACHER

Stage One

Page 14: ER modelling

Possible ER Diagram

STUDENT SUBJECT

TEACHER

Stage two

Page 15: ER modelling

Possible ER Diagram

STUDENT SUBJECT

TEACHER

Stage three

STUDENT SUBJECT

SUBJECT TEACHER