Download as pdf or txt
Download as pdf or txt
You are on page 1of 32

Databases

Topic 4:
Entity Relationship Modelling 2

V1.0 © NCC Education Limited


Entity Relationship Modelling 2 Topic 4 - 4.0

Scope and Coverage


This topic will cover:
• Constructing ER models
• Primary and Foreign keys
• Strong and weak entities
• Identifying problems in ER models
• Problem solving in ER models

V1.0 © NCC Education Limited


Entity Relationship Modelling 2 Topic 4 - 4.0

Learning Outcomes
By the end of this topic, students will be able to:
• Construct an ER model from a scenario
• Understand the purpose of a primary key
• Understand the role of foreign keys
• Recognise strong and weak entities
• Identify and solve problems in ER models

V1.0 © NCC Education Limited


Entity Relationship Modelling 2 Topic 4 - 4.0

Activity - Draw the ER - 1


A GARDENING COMPANY
The company hires out workers as they need to.
Workers in the town stay in lodgings. A lodging
may have many workers in it. We are only
concerned with the workers’ current lodging.
Workers possess certain skills such as ‘Tree
Surgery’ and ‘Garden Design’. They may have
more than one skill.

V1.0 © NCC Education Limited


Entity Relationship Modelling 2 Topic 4 - 4.0

Activity - Draw the ER - 2


A GARDENING COMPANY
The company hires out workers as they need to.
Workers in the town stay in lodgings. A lodging
may have many workers in it. We are only
concerned with the workers’ current lodging.
Workers possess certain skills, such as ‘Tree
Surgery’, and ‘Garden Design’. They may have
more than one skill.

V1.0 © NCC Education Limited


Entity Relationship Modelling 2 Topic 4 - 4.0

Activity - Draw the ER - 3


A GARDENING COMPANY
The company hires out workers as they need to.
Workers in the town stay in Lodgings. A lodging
may have many workers in it. We are only
concerned with the workers’ current lodging.
Workers possess certain Skills such as ‘Tree
Surgery’, and ‘Garden Design’. They may have
more than one skill.
‘Town’ is really an attribute of the Lodging.
We also put uppercase letters at start to conform to UML

V1.0 © NCC Education Limited


Entity Relationship Modelling 2 Topic 4 - 4.0

Activity - Draw the ER - 4


A GARDENING COMPANY
The company hires out workers as they need to.
Workers in the town stay in Lodgings. A lodging
may have many workers in it. We are only
concerned with the workers’ current lodging.
Workers possess certain Skills, such as ‘Tree
Surgery’and ‘Garden Design’. They may have
more than one skill.
NOW TRY AND DRAW...

V1.0 © NCC Education Limited


Entity Relationship Modelling 2 Topic 4 - 4.0

Solution
Worker Worker skill
skill Skill
1 0...* 0...* 1

0...*

Where did the ‘Worker skill’


entity come from?
1
Lodging
lodging

V1.0 © NCC Education Limited


Entity Relationship Modelling 2 Topic 4 - 4.0

Attributes - 1
Client
Primary Key ------------
clientNo(PK)
name
Uniquely identifies each fname
lname
occurrence of an entity telNo

V1.0 © NCC Education Limited


Entity Relationship Modelling 2 Topic 4 - 4.0

Attributes - 2
Client
Foreign Key ------------
Preference
clientNo(PK)
-------------
name
prefType
Links entities fname
maxRent
lname
clientNo(FK)
into relationships telNo

V1.0 © NCC Education Limited


Entity Relationship Modelling 2 Topic 4 - 4.0

Entity Types and Attributes:


Module
Attributes - 1 Module Code(PK)
Module Name
0...*

Taken by
V

Attributes:
0...*
Student
Student No(PK)

Student Name

V1.0 © NCC Education Limited


Entity Relationship Modelling 2 Topic 4 - 4.0

Entity Types and Attributes:


Module
Attributes - 2 Module Code(PK)
Module Name
1

0...*
Student Attributes:
on
Module Code (FK)
Module
Student No (FK)
0...*

1 Attributes:
Student No(PK)
Student
Student Name

V1.0 © NCC Education Limited


Entity Relationship Modelling 2 Topic 4 - 4.0

Entity Types and Attributes - 3


Attributes: Module Module Name
Module Module Code(PK) Code
Module Name QB210 Business Database
1 Applications
0...N QB251 User Centred Systems
Attributes Analysis
Student
on Module Code (FK) QB313 Advanced Business Database
Module Applications
Student No (FK)
0...N
1
Attributes:
Student Student No(PK)
Student Name

V1.0 © NCC Education Limited


Entity Relationship Modelling 2 Topic 4 - 4.0

Entity Types and Attributes - 4


Module Module Name
Attributes: Code
Module Module Code(PK) QB210 Business Database Applications

Module Name QB251 User Centred Systems Analysis


1 QB313 Advanced Business Database
0...* Applications
Attributes
Student Module Code Student ID
on Module Code (FK) QB210 M00002
Module Student No (FK) QB210 M00003
0...* QB251 M00002
1
Attributes:
Student Student No(PK)
Student Name

V1.0 © NCC Education Limited


Entity Relationship Modelling 2 Topic 4 - 4.0

Entity Types and Attributes - 5


Module Module Name
Attributes: Code
Module Module Code(PK) QB210 Business Database
Applications
Module Name QB251 User Centred Systems
1
Analysis
0...* QB313 Advanced Business
Attributes
Student Module Database Applications
Code Student ID
on Module Code (FK) QB210 M00002
Module Student No (FK) QB210 M00003
0...* QB251 M00002
1
Attributes:
Student Student No(PK)
Student Name

V1.0 © NCC Education Limited


Entity Relationship Modelling 2 Topic 4 - 4.0

Strong and Weak Entity Types - 1


• Strong entity type: An entity type that DOES NOT
depend upon another entity type for its existence,
e.g. Student or Employee

• Weak entity type: An entity type that DOES depend


upon another entity type for its existence, e.g.
Grades or Bonuses
– Connolly and Begg

V1.0 © NCC Education Limited


Entity Relationship Modelling 2 Topic 4 - 4.0

Strong and Weak Entity Types - 2


States>
Client Preference

• Without the client, the preference would not exist!


• Strong entity types are also known as parent, owner
or dominant entity types.
• Weak entity types are also known as child,
dependent, or subordinate entities.

V1.0 © NCC Education Limited


Entity Relationship Modelling 2 Topic 4 - 4.0

Strong and Weak Entity Types - 3


• Note that the primary key of a weak entity type
would have to include the primary key of the strong
entity type.

V1.0 © NCC Education Limited


Entity Relationship Modelling 2 Topic 4 - 4.0

Fan Traps – The Problem

0...* 1 1 1...* Department


Staff Campus

V1.0 © NCC Education Limited


Entity Relationship Modelling 2 Topic 4 - 4.0

Fan Traps Campus ID Campus Name

-1 C1 London Campus
C2 Lagos

C3 Cairo

In which Department does Eric work?

Staff ID Name Campus ID (FK) Department ID Name Campus ID (FK)


S1 Eric C2
Hudson D1 Humanities C1
S2 Sandra C1
D2 Computing C2
Smith
S3 Malia C1 D3 Maths C2
Shah
Staff Department

V1.0 © NCC Education Limited


Entity Relationship Modelling 2 Topic 4 - 4.0

Fan Traps – The Solution

1...* 1 1...* 1
Staff Department Campus

V1.0 © NCC Education Limited


Entity Relationship Modelling 2 Topic 4 - 4.0

Fan Traps Campus


ID
Campus Name

-2 C1
C2
London
Lagos
Campus

C3 Cairo

We now know in which department Eric works

Staff ID Name Department ID (FK)


Department ID Name Campus ID (FK)
S1 Eric D3
Hudson D1 Humanities C1
S2 Sandra D1 D2 Computing C2
Smith
D3 Maths C2
S3 Malia D1
Shah
Department
Staff

V1.0 © NCC Education Limited


Entity Relationship Modelling 2 Topic 4 - 4.0

Chasm Trap – The Problem

1 1...* 0...1 0...*


Branch Staff Property

• A branch has many staff members who manage


properties, but not all properties are managed by a
member of staff, and not all staff manage
properties.

V1.0 © NCC Education Limited


Entity Relationship Modelling 2 Topic 4 - 4.0

Chasm Trap - 1
Branch Branch
ID Name Branch Which Branch manages
1 Ilford
‘Hill House’?
2 Redbridge

Staff ID Name Branch ID


(FK) Property
S1 Davinda 1
Staff Property ID Property Staff ID
S2 Roberta 1 Name (FK)
S3 Eddie 2 P1 Yap S1
Mansions
P2 Hill House
P2 Usher S2
House

V1.0 © NCC Education Limited


Entity Relationship Modelling 2 Topic 4 - 4.0

Chasm Trap – The Solution

Staff 0...1 0...*


1 1...* Property
Branch

1 0...*

V1.0 © NCC Education Limited


Entity Relationship Modelling 2 Topic 4 - 4.0

Chasm Trap - 2
Branch Branch We now know which
ID Name Branch Branch manages ‘Hill
1 Ilford
House’
2 Redbridge

Staff ID Name Branch Property


ID (FK)
S1 Davinda 1 Proper Property Staff ID Branch
Staff ty ID Name (FK) ID (FK)
S2 Roberta 1
P1 Yap S1 1
S3 Eddie 2
Mansions
P2 Hill 2
House
P2 Usher S2 2
House

V1.0 © NCC Education Limited


Entity Relationship Modelling 2 Topic 4 - 4.0

Activity – Draw the ER - 1


Beavis is a car hire company.
• They have a number of models of car available for
hire.
• Customers hire cars and this is recorded against a
particular car rather than a model, as Beavis might
have several cars of the same model.
• When a customer wants to reserve a particular
model they can do so; this is recorded against a
model rather than the car.

V1.0 © NCC Education Limited


Entity Relationship Modelling 2 Topic 4 - 4.0

Activity – Draw the ER - 2


• When a car of that model becomes available, it will
be held for the customer.
• When they come in for it, a record is made on the
reservation to say which car satisfied the
reservation.

V1.0 © NCC Education Limited


Entity Relationship Modelling 2 Topic 4 - 4.0

Beavis Car Hire Company

CAR 1 0...* 0...* 1


HIRE

0...* 1
CUSTOMER
1
0...*
0...* 1
MODEL RESERVATION
1 0...*

V1.0 © NCC Education Limited


Entity Relationship Modelling 2 Topic 4 - 4.0

Learning Outcomes – Have We


Met Them?
By the end of this topic, students will be able to:
• Construct an ER model from a scenario
• Understand the purpose of a primary key
• Understand the role of foreign keys
• Recognise strong and weak entities
• Identify and solve problems in ER models

V1.0 © NCC Education Limited


Entity Relationship Modelling 2 Topic 4 - 4.0

References
• Connolly, T. & Begg, C. (2004). Database Systems:
A Practical Approach to Design, Implementation,
and Management, 4th Edition. Addison Wesley.
Chapter 11.

V1.0 © NCC Education Limited


Entity Relationship Modelling 2 Topic 4 - 4.0

Topic 4 – Entity Relationship Modelling 2

Any Questions?

V1.0 © NCC Education Limited

You might also like