ER modelling
description
Transcript of ER modelling
ER modelling
Practice
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
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.
Possible Solution
• Entity– Choc Bar
– Ingredient
• Attribute– Name– Price– Weight– Stock level
– Name – Quantity required– Price/Kg– Stock level– Reorder level
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
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
Possible Solution
• Entity– Customer
– DVD
• Attribute– Name– Address– email– preferred genre
– Name – Duration– Genre– Price
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
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
Possible solution• Entity
– WARD
– NURSE
– PATIENT
– CONSULTANT
• Attribute– Name– Number of beds
– Name – Address
– Name– DOB– Blood group
– Name– Specialism
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
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
Possible ER Diagram
STUDENT SUBJECT
TEACHER
Stage One
Possible ER Diagram
STUDENT SUBJECT
TEACHER
Stage two
Possible ER Diagram
STUDENT SUBJECT
TEACHER
Stage three
STUDENT SUBJECT
SUBJECT TEACHER