You are on page 1of 27

3/10/2017

11e Database Systems Design, Implementation, and Management Coronel | Morris Chapter 4 Entity Relationship (ER) Modeling
11e
Database Systems
Design, Implementation, and Management
Coronel | Morris
Chapter 4
Entity Relationship (ER)
Modeling
©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.

Learning Objectives

In this chapter, you will learn:

The main characteristics of entity relationship components

How relationships between entities are defined, refined, and incorporated into the database design process

How ERD components affect database design and

implementation

That real-world database design often requires the reconciliation of conflicting goals

2

3/10/2017

 

Entity Relationship Model (ERM)

ERM forms the basis of an entity relationship diagram (ERD)

ERD is used to show conceptual database and database’s

main components

Entity Relationship Model (ERM) • ERM forms the basis of an entity relationship diagram (ERD) •
 

3

 

Entity Relationship Model (ERM) (cont…)

Entity Relationship Model (ERM) • ERM forms the basis of an entity relationship diagram (ERD) •
 

4

3/10/2017

 

Entity Relationship Model (ERM) (cont…)

Entities

Entity - refers to the entity set and not to a single entity occurrence

ERD refers to a row as an entity instance or entity occurence

In then Chen, Crow’s Foot, and UML notations, an entity is represented by a rectangle that contains the entity’s name

The entity’s name (i.e. a noun) is normally written in all capital letters

5

 
 

Entity Relationship Model (ERM) (cont…)

Attributes

Characteristics of entities

Examples:

Entity Relationship Model (ERM) (cont …) Entities • Entity - refers to the entity set and
 

6

3/10/2017

Entity Relationship Model (ERM) (cont…) Attributes: Required & Optional Attributes • • Required attribute: must have
Entity Relationship Model (ERM) (cont…)
Attributes: Required & Optional Attributes
Required attribute: must have a value, cannot be left empty
Optional attribute: does not require a value, can be left
empty
Required attributes
Optional attributes
7
Entity Relationship Model (ERM) (cont…)
Attributes: Domains
Domain - set of possible values for a given attribute
Examples:
Grade point average attribute: (0, 4)
Gender attribute: M or F
Salary attribute: >= RM 900
Examination score: (0, 100)
8

3/10/2017

Entity Relationship Model (ERM) (cont…)

Attributes: Composite Identifiers

Composite identifier: primary key composed of more than one attribute

Entity Relationship Model (ERM) (cont …) Attributes: Composite Identifiers • Composite identifier : primary key composed

9

Entity Relationship Model (ERM) (cont…)

Attributes: Composite Identifiers

If CLASS_CODE is used as the primary key:

Entity Relationship Model (ERM) (cont …) Attributes: Composite Identifiers • If CLASS_CODE is used as the

If CRS_CODE and CLASS_SECTION are used as the composite primary key:

Entity Relationship Model (ERM) (cont …) Attributes: Composite Identifiers • If CLASS_CODE is used as the

10

3/10/2017

 

Entity Relationship Model (ERM) (cont…)

Attributes: Composite & Simple Attributes

Composite attribute: attribute that can be subdivided to yield additional attributes (to facilitate detailed queries)

Examples:

ADDRESS attribute can be divided into street, city, state, and

zip code

PHONE_NUMBER attribute can be divided into area code, and exchange number

Simple attribute: attribute that cannot be subdivided

Examples: age, sex, marital status

11

 
 

Entity Relationship Model (ERM) (cont…)

Attributes: Single-valued Attributes

Single-valued attribute: attribute that has only a single value

Example: a person can have only one active passport number Single-valued attribute is not always a simple attribute

Example: part’s serial number is a single-valued attribute but it can be a composite attribute which can be divided into region, plant, shift, and the part number.

Plant MLK-10-05-174657 Region Shift Part number 12

Plant

MLK-10-05-174657

Plant MLK-10-05-174657 Region Shift Part number 12
Plant MLK-10-05-174657 Region Shift Part number 12

Region

Shift

Part number

12

3/10/2017

 

Entity Relationship Model (ERM) (cont…)

Attributes: Multivalued Attributes & Its Implementation

Multivalued attributes: attributes that have many values

Examples:

 

A person may have several college degrees

A person may have several phone numbers

A car may have different colours for its roof, body, and trim

13
13
 
 

Entity Relationship Model (ERM) (cont…)

Attributes: Multivalued Attributes & Its Implementation

How to implement multivalued attributes?

Method 1: Splitting the multivalued attributes into new attributes

Within the original entity, create several new attributes, one for

 

each component of the original multivalued attribute

 
14
14

3/10/2017

Entity Relationship Model (ERM) (cont…)

Attributes: Multivalued Attributes & Its Implementation

Method 1:

Any problem? •
Any problem?

Mini Racing Green by Bryn Pinzgauer (CC BY 2.0)

CAR_VIN: PP8196 CAR_YEAR: 1990 CAR_TOPCOLOR: White CAR_TRIMCOLOR: Silver CAR_BODYCOLOR: Green

After a month, your boss asks you to add another attribute?????!!!!! CAR_INTERIORCOLOR: Black

Demo with Multivalued Attributes.accdb

15

Entity Relationship Model (ERM) (cont…)

Attributes: Multivalued Attributes & Its Implementation

Method 2:

Create a new entity composed of the original multivalued attribute’s components

CAR_COLOR entity is related to the original CAR entity in 1:M relationship

Entity Relationship Model (ERM) (cont…) Attributes: Multivalued Attributes & Its Implementation • Method 2 : •
16
16

3/10/2017

Entity Relationship Model (ERM) (cont…)

Attributes: Multivalued Attributes & Its Implementation

 

Why method 2 is better than method 1?

Allows user to assign as many colors without having to change the table structure

More flexible, expandable solution and compatible with the

 
 

relational model

 

17

 

Entity Relationship Model (ERM) (cont…)

Attributes: Derived Attributes (Computed Attributes)

 

Derived attribute: attribute whose value is calculated from other attributes

Derived using an algorithm. An attribute that does not physically exist within the entity

Referred to as computed attribute

Examples:

 

AGE can be derived from DOB and current date

COST can be derived from the multiplication between UNIT_PRICE and QUANTITY

 

18

3/10/2017

 

Entity Relationship Model (ERM) (cont…)

Attributes: Derived Attributes (Computed Attributes)

Entity Relationship Model (ERM) (cont…) Attributes: Derived Attributes (Computed Attributes) Figure 4.6 - Depiction of a
 

Figure 4.6 - Depiction of a Derived Attribute

19

 
 

Entity Relationship Model (ERM) (cont…)

Attributes: Derived Attributes (Computed Attributes)

Do we need to store derived attributes?

Entity Relationship Model (ERM) (cont…) Attributes: Derived Attributes (Computed Attributes) Figure 4.6 - Depiction of a
 

Table 4.2 - Advantages and Disadvantages of Storing Derived Attributes

20

3/10/2017

 

Entity Relationship Model (ERM) (cont…)

 

Relationships

Association between entities that always operate in both directions

Participants: Entities that participate in a relationship

Relationship name = active or passive verb

Examples:

A STUDENT takes a CLASS A PROFESSOR teaches a CLASS

 

A DEPARTMENT employs a PROFESSOR

A DIVISION is managed by an EMPLOYEE

An AIRCRAFT is flown by a CREW

   

21

 
 

Entity Relationship Model (ERM) (cont…)

 

Relationships

Bidirectional

Examples: CUSTOMER & INVOICE

 

A CUSTOMER may generate many INVOICEs

Each INVOICE is generated by one CUSTOMER

Difficult to model a relationship if ONLY one side of the relationship is known.

Example: A DIVISION is managed by one EMPLOYEE. Is it 1:1 or 1:M relationship? Therefore, you should clarify the second part of the relationship.

An EMPLOYEE may manage many DIVISIONs

or

An EMPLOYEE may manage only one DIVISION

   

22

3/10/2017

Entity Relationship Model (ERM) (cont…)

Connectivity & Cardinality

Connectivity: describes the relationship classification

Cardinality: expresses the minimum and maximum number of entity occurrences associated with one occurrence of related entity

Entity Relationship Model (ERM) (cont…) Connectivity & Cardinality • • Connectivity : describes the relationship classification

Figure 4.7 - Connectivity and Cardinality in an ERD

23

Entity Relationship Model (ERM) (cont…)

Connectivity & Cardinality

•
•

Each professor teaches up to four classes.

Each class is taught by one and only one professor.

Each CLASS entity occurrence is associated with one and only one entity occurrence in PROFESSOR

PK in the PROFESSOR table appear once or not more than four times in the CLASS table

24

3/10/2017

Entity Relationship Model (ERM) (cont…)

Connectivity & Cardinality

The placement of the cardinalities in the Chen notation

• The placement of the cardinalities in the Chen notation • The placement of the cardinalities

The placement of the cardinalities in the Crow’s Foot notation

(0,N) (1,1)
(0,N)
(1,1)

25

Entity Relationship Model (ERM) (cont…)

Existence Dependence

Entity Relationship Model (ERM) (cont…) Existence Dependence Example: EMPLOYEE claims DEPENDENT Example: PART is supplied by

Example: EMPLOYEE claims DEPENDENT

Example: PART is supplied by VENDOR (some parts are produced in-house)

26

3/10/2017

 

Entity Relationship Model (ERM) (cont…)

Relationship Strength

Based on how the primary key of a related entity is defined.

To implement a relationship, the primary key of one entity (normally on the “one” side (parent entity) of the 1:M relationship) appears as a foreign key in the related entity (mostly the entity on the “many” side (child entity) of the 1:M relationship)

Entity Relationship Model (ERM) (cont…) Relationship Strength • Based on how the primary key of a
 

27

 
 

Entity Relationship Model (ERM) (cont…)

Relationship Strength: Weak (Non-identifying) Relationships

Primary key of the related entity does not contain a primary key component of the parent entity. Example:

Entity Relationship Model (ERM) (cont…) Relationship Strength • Based on how the primary key of a

Figure 4.8 - A Weak (Non-Identifying) Relationship between COURSE and CLASS

Entity Relationship Model (ERM) (cont…) Relationship Strength • Based on how the primary key of a
 

28

3/10/2017

Entity Relationship Model (ERM) (cont…)

Relationship Strength: Weak (Non-identifying) Relationships

Entity Relationship Model (ERM) (cont…) Relationship Strength: Weak (Non-identifying) Relationships 29

29

Entity Relationship Model (ERM) (cont…)

Relationship Strength: Strong(Identifying) Relationships

Primary key of the related entity contains a primary key component of the parent entity. Example:

Entity Relationship Model (ERM) (cont…) Relationship Strength: Strong(Identifying) Relationships • Primary key of the related entity

Figure 4.9 - A Strong (Identifying) Relationship between COURSE and CLASS

Entity Relationship Model (ERM) (cont…) Relationship Strength: Strong(Identifying) Relationships • Primary key of the related entity

30

3/10/2017

Entity Relationship Model (ERM) (cont…) Relationship Strength: Strong(Identifying) Relationships 31 Entity Relationship Model (ERM) (cont…) Relationship
Entity Relationship Model (ERM) (cont…)
Relationship Strength: Strong(Identifying) Relationships
31
Entity Relationship Model (ERM) (cont…)
Relationship Strength: Weak & Strong (notation line)
Weak (non-identifying) relationship
Strong (identifying) relationship
32

3/10/2017

Entity Relationship Model (ERM) (cont…)

Weak Entities

Conditions:

 

Existence-dependent; it cannot exist without the entity with which it has a relationship. Eg: DEPENDENT entity

Has a primary key that is partially or totally derived from parent entity in the relationship

Database designer determines whether an entity is weak based on business rules

Entity Relationship Model (ERM) (cont…) Weak Entities • Conditions: • Existence-dependent; it cannot exist without the

33

Entity Relationship Model (ERM) (cont…)

Weak Entities

Entity Relationship Model (ERM) (cont…) Weak Entities Figure 4.10 - A Weak Entity in an ERD

Figure 4.10 - A Weak Entity in an ERD

34

3/10/2017

Entity Relationship Model (ERM) (cont…)

Weak Entities

Entity Relationship Model (ERM) (cont…) Weak Entities Figure 4.11 - A Weak Entity in a Strong

Figure 4.11 - A Weak Entity in a Strong Relationship

35

Entity Relationship Model (ERM) (cont…)

Relationship Participation

• One entity occurrence does not require a corresponding entity occurrence in a particular relationship •
• One entity occurrence does not
require a corresponding entity
occurrence in a particular
relationship
• Eg: some COURSEs do not
generate a CLASS
Optional participation
• Eg: CLASS cannot exist without a COURSE • One entity occurrence requires a corresponding entity
• Eg: CLASS cannot exist without a
COURSE
• One entity occurrence requires a
corresponding entity occurrence
in a particular relationship
Mandatory participation

36

3/10/2017

Entity Relationship Model (ERM) (cont…)

Relationship Participation

Entity Relationship Model (ERM) (cont…) Relationship Participation Table 4.3 - Crow’s Foot Symbols 37

Table 4.3 - Crow’s Foot Symbols

37

Entity Relationship Model (ERM) (cont…)

Relationship Participation

Example:

PROFESSOR teaches CLASS

Entity Relationship Model (ERM) (cont…) Relationship Participation • Example: • PROFESSOR teaches CLASS Connectivity • CLASS

Connectivity

CLASS is optional to

PROFESSOR (a professor

PROFESSOR (a professor

might not teach any class)

PROFESSOR is mandatory

to CLASS (a class must be taught by a professor)

to CLASS (a class must be taught by a professor)

Cardinality A professor may teach no classes or a maximum of three classes Each class is taught by one and only one professor

(0,3)

(1,1)

38

3/10/2017

 

Entity Relationship Model (ERM) (cont…)

Relationship Participation

 

Example:

 

COURSE generates CLASS

• CLASS is optional

CLASS is optional

A course without any class is allowed

• CLASS is mandatory

CLASS is mandatory

A course without any class is not allowed

39

 
 

Entity Relationship Model (ERM) (cont…)

Relationship Degree

 

Indicates the number of entities or participants associated with a relationship

 
Entity Relationship Model (ERM) (cont…) Relationship Participation • Example: • COURSE generates CLASS • CLASS is
 

40

3/10/2017

 

Entity Relationship Model (ERM) (cont…)

Relationship Degree: Unary

Unary relationship: Association is maintained within a single entity

Example: an employee in the EMPLOYEE is the manager for one or more employees within the same entity

Entity Relationship Model (ERM) (cont…) Relationship Degree: Unary • Unary relationship : Association is maintained within

The example is also known as recursive relationship Relationship exists between occurrences of the same entity set

41

 
 

Entity Relationship Model (ERM) (cont…)

Relationship Degree: Binary

Binary relationship: Two entities are associated

Example: a PROFESSOR teaches one or more CLASSes

Entity Relationship Model (ERM) (cont…) Relationship Degree: Unary • Unary relationship : Association is maintained within
 

42

3/10/2017

Entity Relationship Model (ERM) (cont…)

Relationship Degree: Ternary

Ternary relationship: Three entities are associated

Example:

A DOCTOR writes one or more PRESCRIPTIONs

A PATIENT may receive one or more PRESCRIPTIONs

A DRUG may appear in one or more PRESCRIPTIONs

Entity Relationship Model (ERM) (cont…) Relationship Degree: Ternary • Ternary relationship : Three entities are associated
43
43

Entity Relationship Model (ERM) (cont…)

Relationship Degree: Ternary

Implementation of the ternary relationships 44 •
Implementation of the ternary relationships
44

3/10/2017

Entity Relationship Model (ERM) (cont…)

Recursive relationships

Recursive relationships 1:1 unary relationship 1:M unary relationship M:N unary relationship

45

Entity Relationship Model (ERM) (cont…)

Recursive relationships

Example 1: An EMPLOYEE may be married to one and only one other EMPLOYEE (1:1

unary relationship)

Example 2: an employee in the EMPLOYEE is the manager for one or more employees within the same entity

Example 3: a COURSE may be a prerequisite to many other COURSEs, and each COURSE may have other COURSEs as

prerequisites (M:N unary

relationship)

Entity Relationship Model (ERM) (cont…) • • • Recursive relationships Example 1 : An EMPLOYEE may
Entity Relationship Model (ERM) (cont…) • • • Recursive relationships Example 1 : An EMPLOYEE may
Entity Relationship Model (ERM) (cont…) • • • Recursive relationships Example 1 : An EMPLOYEE may
Entity Relationship Model (ERM) (cont…) • • • Recursive relationships Example 1 : An EMPLOYEE may
Entity Relationship Model (ERM) (cont…) • • • Recursive relationships Example 1 : An EMPLOYEE may

46

3/10/2017

Entity Relationship Model (ERM) (cont…)

Recursive relationships

Entity Relationship Model (ERM) (cont…) Recursive relationships • • 1:1 unary recursive relationship An EMPLOYEE may

1:1 unary recursive relationship

An EMPLOYEE may be married to one and only one other EMPLOYEE

An EMPLOYEE may be married to one and only one other EMPLOYEE

James Ramirez

Loiuse Ramirez

47

Entity Relationship Model (ERM) (cont…)

Recursive relationships

1:M unary recursive relationship

An employee in the EMPLOYEE is the manager for one or more employees within the same entity

Entity Relationship Model (ERM) (cont…) Recursive relationships • • 1:M unary recursive relationship An employee in
48
48

3/10/2017

 

Entity Relationship Model (ERM) (cont…)

Recursive relationships

Another example of 1:M unary recursive relationship

A rotor assembly is composed of many parts, but each part is used to create only one rotor assembly

49
49
 
 

Entity Relationship Model (ERM) (cont…)

Recursive relationships

Recursive relationships

M:N unary recursive relationship

COURSE requires COURSE

• MATH-243 is a prerequisite to QM-261 & QM-362 • MATH-243 & QM-261 are prerequisite to
MATH-243 is a prerequisite to QM-261 &
QM-362
MATH-243 & QM-261 are prerequisite to
50
QM-362

3/10/2017

 

Entity Relationship Model (ERM) (cont…)

Recursive relationships

Another example of M:N unary recursive relationship (PART contains PART)

51
51
 
 

Entity Relationship Model (ERM) (cont…)

Associative (Composite) Entities

Also known as composite or bridge entities

Used to represent an M:N relationship between two or more entities

Is in a 1:M relationship with the parent entities

Composed of the primary key attributes of each parent entity

May also contain additional attributes that play no role in connective process

 

52

3/10/2017

Entity Relationship Model (ERM) (cont…) Associative (Composite) Entities 53 Entity Relationship Model (ERM) (cont…) Associative (Composite)
Entity Relationship Model (ERM) (cont…)
Associative (Composite) Entities
53
Entity Relationship Model (ERM) (cont…)
Associative (Composite) Entities
Figure 4.23 - Converting the M:N Relationship into Two 1:M Relationships
54