Professional Documents
Culture Documents
Database Systems
Unit 7 :
Entity
Relationship
Modeling (ERM)
(Part 1)
Topic 7
Objective :
At the end of this unit, you should be able to:
Learn the key elements in ER modeling.
Understand different types of binary
relationships in ER Modeling.
Understand ER diagrams using different
notations
Topic 7
What is Entity
Relationship (ER)
Modelling
Topic 7
The 3-Level
Architecture
of Database
Topic 7
What is ER Modelling?
In this study, Relational Model is adopted.
Entity Relationship (ER) modeling is a detailed,
logical representation of the data for an
organization or for a business area.
4 key elements in ER modeling.
o The entities in the business environment,
o The attributes(or properties) of both the entities and
their relationships,
o The identifiers to identify entity instances, and
o The relationships (or associations) among those entities.
Topic 7
Topic 7
Topic 7
Topic 7
Entity
An entity is an identifiable object (a person,
a place, a thing, or an event) about which
data are to be collected and stored.
Entity can be tangible; (e.g.):
o
o
EMPLOYEE
CUSTOMER
( Relation, Table)
PAYMENT
ORDER
PAYMENT
CUSTOMER
EMPLOYEE
ORDER
Topic 7
Attribute
An attribute is a characteristic of an Entity. It
is also known as the field of a table.
For example, CUSTOMER entity has the following
attributes:
Note: A Primary key is underlined
CustomerId
CustomerName
BirthDate
CUSTOMER
CustomerID
CustomerName
Phone
CUSTOMER
Gender
BirthDate
Gender
Phone
10
Topic 7
Domain
Field name
Data type
Field length
CustomerName BirthDate
Gender Phone
C-01
Rose Mary
12-Sep-1998
61111111
C-02
Peter Leong
05-Mar-2000
62222222
C-03
Josephine
29-May-1996
63333333
11
Topic 7
Entity Instance
An instance of an entity is shown in the following
example:
EMPLOYEE
An Instance of EMPLOYEE
Employee_ID
Eng-012
Name
Peter Leong
Designation
Supervisor
Salary
$4,500
Working Year
Designation
Salary
Working Year
Eng-012
Peter Leong
Supervisor
$4,500
Sales-182
Jessie Chan
Sales Mgr
$6,000
12
12
Topic 7
Types of Entity
13
Topic 7
Or as a relation;
CUSTOMER
CustName
Company
Phone Number
E-mail Address
IT1768 Database Systems
14
Topic 7
Emp_id
Emp_Name
EMPLOYEE
1:N
Dependent_id
DEPENDENT
HAS
Emp_sex
Dependent_sex
Dependent_age
15
Topic 7
Weak Entity
Weak entity has primary key that is partially or
totally derived from parent entity.
16
Topic 7
Weak Entity
A weak relation inherits the key attribute of the associated
strong relation, together with its own key attribute.
Strong Entity : ORDER
OrderNum
OrderDate
Has Items
SalesPrice
OrderNum
ItemNum
PartDesc
Qty
Cost
17
Topic 7
PRODUCT
Version_Id
Product_Id
Prod_Name
1:N
VERSION
Update
Price
Description
Example:
Client Id
Client_Id
Client_Name
CLIENT
1:N
Prefrence_Id
PREFERENCE
Stated
Address
IT1768 Database Systems
Prefrence_type
18
Topic 7
Supertype/Subtype Entities
19
Topic 7
Supertype/Subtype entities
20
Topic 7
Supertype/Subtype entities
GstRegis_no
Client_Name
Date_transact
Amount_Due
Client_No
CLIENT
Profession
Address
Phone
Person_contact
Payment_class
Country_id
There are various kinds of clients which share common attributes among them.
IT1768 Database Systems
21
Topic 7
Supertype/Subtype entities
By Super-type/Sub-type entities:
CLIENT ( Client_No, Client_Name , Amount_due)
Indi_Client ( Profession, Address ) attribute before modeling
Corp_Client ( GstRegis_no, Payment_class, Date_transact ) before modeling
Overseas_Client ( Country_id, Person_contact, Phone ) before modeling
CLIENT
Indi_Client
Corp_Client
Generalization or
IS-A relationship
Overseas_Client
*1 indicates that a client entity must belong to one, and only one subtype
Generalization is a process of defining a more general entity type from a set of
more specialized entity types.
IT1768 Database Systems
22
Topic 7
Supertype/Subtype Entities
By Generalization hierarchy
- Supertype has shared attribute
- Subtypes have unique attributes
Entities in Subtypes inherit attributes from their Supertype
entity class. This has to be reflected in ER modeling.
Exercise:
Think of a Supertype/Subtype example for an entity : EMPLOYEE
23
Topic 7
Supertype/Subtype entities
24
Topic 7
Relationship
25
Topic 7
Relationship
A relationship is a link/association between two entities.
The degree of the relationship refer to the number of
associated entities in a relationship.
Relationship of degree 2 are called binary relationship.
Most relationships in the databases are binary.
Relationship of degree 3 are Ternary, 4 are Quaternary.
Action
Married
Married
Ternary
Quaternary
Binary
26
Topic 7
Binary Relationship
3 types of binary relationships :
One-to-one
(1:1)
One-to-many
(1:N) or
Many-to-one (N:1)
1:1
action
N:1
action
M:N
Many-to-Many
(N:M)
action
27
1:1 Relationship
EMPLOYEE
Topic 7
Pay
PAYCHECK
a1
b1
a2
b2
a3
b3
a4
b4
EMPLOYEE
IT1768 Database Systems
PAYCHECK
PC_ENG-02
Back
28
Topic 7
1:1 Relationship
1
EMPLOYEE
Pay
PAYCHECK
PAYCHECK
EMPLOYEE
PayCode
Amount Emp_ID
PC_ENG-02
5000
P622
Q583
Rosidah
QA Exec
PC_QA-03
4200
Q583
E563
Raymond
Machinist
PC_Prod-25
3200
E563
S754
Kelly
Sales Exec
PC_SA-15
3800
S754
Emp_ID
EName
P622
Designation
29
Relationship :
CUSTOMER
for
Topic 7
ACCOUNTS
a1
b1
a2
b2
a3
b3
FD_130-02
SD_130-12
b4
CUSTOMER
IT1768 Database Systems
ACCOUNTS
Back
30
Topic 7
1 : N Relationship
CUSTOMER
for
ACCOUNTS
ACCOUNTS
CUSTOMER
Cust_ID
CName
AccCode
Amount
DateCreated
Cust_ID
C8532
Judy
FD_130-02
5000
25-Oct-2008
C8532
C8533
Brayan
SV_130-12
1200
12-Jul-2006
C8532
C8534
Sandra
STD_12-03
20000
10-May-2005
C8533
C8535
Winnie
SV_132-11
2000
24-Jun-2006
C8533
INV_15-32
30000
12-Jan-2007
C8533
SV_130_20 3200
09-Aug-2006
C8534
SV_140-33
4000
23-Dec-2006
C8535
FD_140-54
10000
19-Nov-2008
C8535
INV_15-66
25000
08-Mar-2007
C8535
31
Topic 7
M:N Relationship
In many-to-many relationship, One instance of a given
entity is related to many instances of another specific entity
and vice versa.
For example; a student can enrol in several modules and a particular
module can be registered by many students.
Chris
a1
b1
IT2761
Joyce
a2
b2
IT2762
a3
b3
IT2765
a4
b4
IT2766
Rose
Steve
STUDENT
IT1768 Database Systems
MODULES
32
Topic 7
M : N Relationship
M
STUDENT
Enrol
MODULES
AdminNo
StudName
Mod_ID
Description
Semester
081111A
Chris
IT2761
Database Mgt
S1
081111A
Chris
IT2762
Web Applications
S1
082222B
Joyce
IT2761
Database Mgt
S1
082222B
Joyce
IT2762
Web Applications
S1
083333C
Rose
IT2765
Networking
S1
083333C
Rose
IT2766
Software Engrg
S2
084444D
Steve
IT2766
Software Engrg
S1
33
Topic 7
Relationship - Cardinality
Cardinality refers to the number of times instances
in one entity can be related to instances in another
entity. For example:
One instance in an entity refers to one and only one
instance in the related entity (1:1)
One instance in an entity refers to one or more instances
in the related entity (1:M)
One or more instances in an entity refer to one or more
instances in the related entity (M:M)
Refer
Refer
Refer
34
Topic 7
Relationship - Cardinality
Kroenkes and Crows Foot notations include
maximum and minimum cardinalities in the
relationships. For example:
By Kroenkes Notation
SPECIALIST
Maximum Cardinality
1:N
SERVICE
PROVIDES
Minimum Cardinality
SPECIALIST
PROVIDES
SERVICE
Minimum Cardinality
IT1768 Database Systems
35
Topic 7
Recursive Relationships
Example 1:
STUDENT
1:N
STUDENT
1:N
Share ROOMS-WITH
STUDENT
Share ROOMS-WITH
IT1768 Database Systems
36
Topic 7
Recursive Relationships
EMPLOYEE
is supervised by
An employee manager
supervises other employees
A supervisor supervises numerous employees
AND an employee is supervised by one or few
supervisors
IT1768 Database Systems
37
Topic 7
Recursive Relationships
Examples:
PERSON
Father of / Son of
A person may be the father of
one or many persons AND a
person has one father
38
Topic 7
The ER Modelling
Notations
39
Topic 7
Chens notation
Kroenkes notation
Crows Feet notation
UML notation (Unified Modelling Language)
Others
40
Topic 7
41
Topic 7
42
Topic 7
CUSTOMER
1:N
ORDER
Places
1:N
Has
Items
ITEMS
Topic 7
44
Topic 7
45
Topic 7
COUNTRY
1
Adopts
CURRENCY
Name
CURRENCY
Adopts
Continent
CUSTOMER
N
Places
Symbol
CUSTOMER
ORDER
Name
ORDER
Places
Contact
EMPLOYEE
N
Possess
EmpID
EmpName
OrderID
Date
EMPLOYEE
SKILL
Name
SKILL
Possess
SkillCode
Description
46
Topic 7
COUNTRY
1
Adopts
Kroenkes Notation
COUNTRY
CURRENCY
Name
Continent
CUSTOMER
N
Places
EMPLOYEE
N
Possess
ORDER
Name
Adopts
SKILL
EmpID
Name
Symbol
ORDER
1:N
Places
EMPLOYEE
EmpName
1:1
CUSTOMER
Contact
CURRENCY
OrderID
Date
SKILL
M:N
Possess
SkillCode
Description
47
Topic 7
Summary
An ER diagram consists of entity types, attributes
and relationships.
Entity types can be classified as strong, weak,
supertype/subtype.
Subtypes inherit attributes from the super-type
A relationship type can involve
one(unary/recursive), two(binary), three (ternary)
or four (quaternary) entity types.
The three main notations in Data modeling are
Chens, Kroenkes and Crows Foot notation.
IT1768 Database Systems
48