Sei sulla pagina 1di 32

Databases

Topic 4:
Entity Relationship Modelling 2

V1.0 NCC Education Limited


Entity Relationship Modelling 2 Topic 4 - 4.2

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.3

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.4

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.5

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.6

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.7

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
Surgeryand 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.8

Solution
Worker Worker skill

skill 1 Skill
1 0...* 0...*

0...*

Where did the Worker skill


entity come from?
1

Lodging
lodging

V1.0 NCC Education Limited


Entity Relationship Modelling 2 Topic 4 - 4.9

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

V1.0 NCC Education Limited


Entity Relationship Modelling 2 Topic 4 - 4.10

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

V1.0 NCC Education Limited


Entity Relationship Modelling 2 Topic 4 - 4.11

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.12

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.13

Entity Types and Attributes - 3


Attributes: Module Module Name
Module Module Code(PK) Code
QB210 Business Database Applications
Module Name
1
QB251 User Centred Systems Analysis
0...N
Attributes QB313 Advanced Business Database
Student Applications
on Module Code (FK)
Module
Student No (FK)
0...N
Student No Student
1 Name
Attributes: M00001 Amina Begum
Student Student No(PK) M00002 Sarah Aka
Student Name M00003 Dave Smith

V1.0 NCC Education Limited


Entity Relationship Modelling 2 Topic 4 - 4.14

Entity Types and Attributes - 4


Module Module Name
Attributes: Code
Module QB210 Business Database Applications
Module Code(PK)
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 QB210 M00003
Student No (FK)
QB251 M00002
0...*
1 Student No Student
Attributes:
Name
Student Student No(PK) M00001 Amina Begum
M00002 Sarah Aka
Student Name
M00003 Dave Smith

V1.0 NCC Education Limited


Entity Relationship Modelling 2 Topic 4 - 4.15

Entity Types and Attributes - 5


Module Module Name
Attributes: Code
Module QB210 Business Database
Module Code(PK)
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 QB210 M00003
Student No (FK)
QB251 M00002
0...*
1 Student No Student
Attributes:
Name
Student Student No(PK) M00001 Amina Begum
M00002 Sarah Aka
Student Name
M00003 Dave Smith

V1.0 NCC Education Limited


Entity Relationship Modelling 2 Topic 4 - 4.16

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.17

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.18

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.19

Fan Traps The Problem

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

V1.0 NCC Education Limited


Entity Relationship Modelling 2 Topic 4 - 4.20

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
Smith D2 Computing C2

S3 Malia C1 D3 Maths C2
Shah

Staff Department

V1.0 NCC Education Limited


Entity Relationship Modelling 2 Topic 4 - 4.21

Fan Traps The Solution

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

V1.0 NCC Education Limited


Entity Relationship Modelling 2 Topic 4 - 4.22

Fan Traps Campus


ID
Campus Name

-2 C1 London
Campus
C2 Lagos

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.23

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.24

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.25

Chasm Trap The Solution

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


Property
Branch
1 0...*

V1.0 NCC Education Limited


Entity Relationship Modelling 2 Topic 4 - 4.26

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 S2 Roberta 1
ty ID Name (FK) ID (FK)
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.27

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.28

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.29

Beavis Car Hire Company

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

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

V1.0 NCC Education Limited


Entity Relationship Modelling 2 Topic 4 - 4.30

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.31

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.32

Topic 4 Entity Relationship Modelling 2

Any Questions?

V1.0 NCC Education Limited

Potrebbero piacerti anche