chapter 4 · • each oval contains the name of ... – each department may offer courses – each...

35
1 4 1 Chapter 4 Entity Relationship (ER) Modeling Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel 4 2 In this chapter, you will learn: The main characteristics of entity relationship components How relationships between entities are defined and refined and how those relationships are 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

Upload: lamkien

Post on 11-Apr-2018

217 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Chapter 4 · • Each oval contains the name of ... – Each department may offer courses – Each department may have many ... a single department – Each student has an advisor

1

4

1

Chapter 4

Entity Relationship (ER) Modeling

Database Systems:

Design, Implementation, and Management,

Seventh Edition, Rob and Coronel

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

4

2

In this chapter, you will learn:

• The main characteristics of entity relationship

components

• How relationships between entities are defined and

refined and how those relationships are 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

Page 2: Chapter 4 · • Each oval contains the name of ... – Each department may offer courses – Each department may have many ... a single department – Each student has an advisor

2

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

4

3

The Entity Relationship (ER) Model

• ER model forms the basis of an ER diagram

• ERD represents conceptual database as viewed by end user

• ERDs depict database’s main components:

– Entities

– Attributes

– Relationships

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

4

4

Entities

• Refers to entity set and not to single entity

occurrence

• Corresponds to table and not to row in relational

environment

• In both Chen and Crow’s Foot models, entity is

represented by rectangle containing entity’s

name

• Entity name, a noun, is usually written in capital

letters

Page 3: Chapter 4 · • Each oval contains the name of ... – Each department may offer courses – Each department may have many ... a single department – Each student has an advisor

3

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

4

5

Attributes

• Characteristics of entities

• In Chen model, attributes are represented by

ovals and are connected to entity rectangle with

a line

• Each oval contains the name of attribute it

represents

• In Crow’s Foot model, attributes are written in

attribute box below entity rectangle

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

4

6

Attributes (continued)

Page 4: Chapter 4 · • Each oval contains the name of ... – Each department may offer courses – Each department may have many ... a single department – Each student has an advisor

4

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

4

7

Domains

• Attributes have domain

– Domain is attribute’s set of possible values

• Attributes may share a domain

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

4

8

Identifiers (Primary Keys)

• Underlined in the ERD

• Key attributes are also underlined in frequently used table structure shorthand

Page 5: Chapter 4 · • Each oval contains the name of ... – Each department may offer courses – Each department may have many ... a single department – Each student has an advisor

5

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

4

9

Composite Primary Keys

• Primary keys ideally composed of only single attribute

• Possible to use a composite key

– Primary key composed of more than one

attribute

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

4

10

Composite Primary Keys (continued)

Page 6: Chapter 4 · • Each oval contains the name of ... – Each department may offer courses – Each department may have many ... a single department – Each student has an advisor

6

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

4

11

Composite and Simple Attributes

• Composite attribute can be subdivided

• Simple attribute cannot be subdivided

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

4

12

Single-Valued Attributes

• Single-value attribute can have only a single value

Page 7: Chapter 4 · • Each oval contains the name of ... – Each department may offer courses – Each department may have many ... a single department – Each student has an advisor

7

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

4

13

Multivalued Attributes

• Multivalued attributes can have many values

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

4

14

Multivalued Attributes (continued)Car can have

many colors

Page 8: Chapter 4 · • Each oval contains the name of ... – Each department may offer courses – Each department may have many ... a single department – Each student has an advisor

8

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

4

15

Resolving Multivalued Attribute Problems

• Although conceptual model can handle M:N

relationships and multivalued attributes, you

should not implement them in relational DBMS

– Within original entity, create several new

attributes, one for each of the original multivalued

attribute’s components

• Can lead to major structural problems in table

– Create new entity composed of original multivalued attribute’s components

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

4

16

Resolving Multivalued Attribute Problems (continued)

Page 9: Chapter 4 · • Each oval contains the name of ... – Each department may offer courses – Each department may have many ... a single department – Each student has an advisor

9

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

4

17

Resolving Multivalued Attribute Problems (continued)

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

4

18

Resolving Multivalued Attribute Problems (continued)

Page 10: Chapter 4 · • Each oval contains the name of ... – Each department may offer courses – Each department may have many ... a single department – Each student has an advisor

10

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

4

19

Derived Attributes

• Attribute whose value may be calculated (derived) from other attributes

• Need not be physically stored within database

• Can be derived by using an algorithm

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

4

20

Derived Attributes (continued)

Page 11: Chapter 4 · • Each oval contains the name of ... – Each department may offer courses – Each department may have many ... a single department – Each student has an advisor

11

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

4

21

Derived Attributes (continued)

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

4

22

Relationships

• Association between entities

• Participants are entities that participate in a relationship

• Relationships between entities always operate in

both directions

• Relationship can be classified as 1:M

• Relationship classification is difficult to establish if

know only one side of the relationship

Page 12: Chapter 4 · • Each oval contains the name of ... – Each department may offer courses – Each department may have many ... a single department – Each student has an advisor

12

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

4

23

Connectivity and Cardinality

• Connectivity

– Used to describe the relationship classification

• Cardinality

– Expresses minimum and maximum number of

entity occurrences associated with one

occurrence of related entity

• Established by very concise statements known as business rules

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

4

24

Connectivity and Cardinality (continued)

Page 13: Chapter 4 · • Each oval contains the name of ... – Each department may offer courses – Each department may have many ... a single department – Each student has an advisor

13

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

4

25

Existence Dependence

• Existence dependence

– Exist in database only when it is associated with another related entity occurrence

• Existence independence

– Entity can exist apart from one or more related entities

– Sometimes refers to such an entity as strong or regular entity

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

4

26

Relationship Strength

• Weak (non-identifying) relationships

– Exists if PK of related entity does not contain

PK component of parent entity

• Strong (Identifying) Relationships

– Exists when PK of related entity contains PK

component of parent entity

Page 14: Chapter 4 · • Each oval contains the name of ... – Each department may offer courses – Each department may have many ... a single department – Each student has an advisor

14

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

4

27

Weak (Non-Identifying) Relationships

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

4

28

Weak (Non-Identifying) Relationships (continued)

Page 15: Chapter 4 · • Each oval contains the name of ... – Each department may offer courses – Each department may have many ... a single department – Each student has an advisor

15

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

4

29

Strong (Identifying) Relationships

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

4

30

Weak Entities

• Weak entity meets two conditions

– Existence-dependent

• Cannot exist without entity with which it has a relationship

– Has primary key that is partially or totally derived

from parent entity in relationship

• Database designer usually determines whether

an entity can be described as weak based on

business rules

Page 16: Chapter 4 · • Each oval contains the name of ... – Each department may offer courses – Each department may have many ... a single department – Each student has an advisor

16

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

4

31

Weak Entities (continued)

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

4

32

Weak Entities (continued)

Page 17: Chapter 4 · • Each oval contains the name of ... – Each department may offer courses – Each department may have many ... a single department – Each student has an advisor

17

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

4

33

Relationship Participation

• Optional participation

– One entity occurrence does not require

corresponding entity occurrence in particular

relationship

• Mandatory participation

– One entity occurrence requires corresponding

entity occurrence in particular relationship

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

4

34

Relationship Participation (continued)

Page 18: Chapter 4 · • Each oval contains the name of ... – Each department may offer courses – Each department may have many ... a single department – Each student has an advisor

18

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

4

35

Relationship Participation (continued)

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

4

36

Relationship Participation (continued)

Page 19: Chapter 4 · • Each oval contains the name of ... – Each department may offer courses – Each department may have many ... a single department – Each student has an advisor

19

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

4

37

Relationship Participation (continued)

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

4

38

Relationship Degree

• Indicates number of entities or participants associated with a relationship

• Unary relationship

– Association is maintained within single entity

• Binary relationship

– Two entities are associated

• Ternary relationship

– Three entities are associated

Page 20: Chapter 4 · • Each oval contains the name of ... – Each department may offer courses – Each department may have many ... a single department – Each student has an advisor

20

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

4

39

Relationship Degree (continued)

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

4

40

Relationship Degree (continued)

Page 21: Chapter 4 · • Each oval contains the name of ... – Each department may offer courses – Each department may have many ... a single department – Each student has an advisor

21

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

4

41

Recursive Relationships

• Relationship can exist between occurrences of the same entity set

• Naturally found within unary relationship

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

4

42

Recursive Relationships

(continued)

Page 22: Chapter 4 · • Each oval contains the name of ... – Each department may offer courses – Each department may have many ... a single department – Each student has an advisor

22

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

4

43

Recursive Relationships (continued)

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

4

44

Recursive Relationships (continued)

Page 23: Chapter 4 · • Each oval contains the name of ... – Each department may offer courses – Each department may have many ... a single department – Each student has an advisor

23

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

4

45

Recursive Relationships (continued)

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

4

46

Recursive Relationships (continued)

Page 24: Chapter 4 · • Each oval contains the name of ... – Each department may offer courses – Each department may have many ... a single department – Each student has an advisor

24

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

4

47

Recursive Relationships (continued)

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

4

48

Composite Entities

• Also known as bridge entities

• Composed of primary keys of each of the entities to be connected

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

Page 25: Chapter 4 · • Each oval contains the name of ... – Each department may offer courses – Each department may have many ... a single department – Each student has an advisor

25

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

4

49

Composite Entities (continued)

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

4

50

Composite Entities (continued)

Page 26: Chapter 4 · • Each oval contains the name of ... – Each department may offer courses – Each department may have many ... a single department – Each student has an advisor

26

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

4

51

Composite Entities (continued)

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

4

52

Developing an ER Diagram

• Database design is iterative rather than linear or sequential process

• Iterative process

– Based on repetition of processes and

procedures

Page 27: Chapter 4 · • Each oval contains the name of ... – Each department may offer courses – Each department may have many ... a single department – Each student has an advisor

27

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

4

53

Developing an ER Diagram (continued)

• Building an ERD usually involves the following

activities:

– Create detailed narrative of organization’s description of operations

– Identify business rules based on description of operations

– Identify main entities and relationships from business rules

– Develop initial ERD

– Identify attributes and primary keys that adequately describe entities

– Revise and review ERD

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

4

54

Developing an ER Diagram (continued)

• Tiny College

– Tiny College is divided into several schools

• Each school is composed of several departments

– Each department may offer courses

– Each department may have many professors assigned to it

– Each professor may teach up to four classes; each class is section of course

– Student may enroll in several classes, but (s)he takes each class only once during any given enrollment period

Page 28: Chapter 4 · • Each oval contains the name of ... – Each department may offer courses – Each department may have many ... a single department – Each student has an advisor

28

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

4

55

Developing an ER Diagram (continued)

• Tiny College (continued)

– Each department has several students

• Each student has only a single major and is associated with

a single department

– Each student has an advisor in his or her department

• Each advisor counsels several students

– The relationship between class is taught in a room and the room in the building

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

4

56

Developing an ER Diagram (continued)

Page 29: Chapter 4 · • Each oval contains the name of ... – Each department may offer courses – Each department may have many ... a single department – Each student has an advisor

29

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

4

57

Developing an ER Diagram (continued)

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

4

58

Developing an ER Diagram (continued)

Page 30: Chapter 4 · • Each oval contains the name of ... – Each department may offer courses – Each department may have many ... a single department – Each student has an advisor

30

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

4

59

Developing an ER Diagram (continued)

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

4

60

Developing an ER Diagram (continued)

Page 31: Chapter 4 · • Each oval contains the name of ... – Each department may offer courses – Each department may have many ... a single department – Each student has an advisor

31

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

4

61

Developing an ER Diagram (continued)

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

4

62

Developing an ER Diagram (continued)

Page 32: Chapter 4 · • Each oval contains the name of ... – Each department may offer courses – Each department may have many ... a single department – Each student has an advisor

32

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

4

63

Developing an ER Diagram (continued)

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

4

64

Developing an ER Diagram (continued)

Page 33: Chapter 4 · • Each oval contains the name of ... – Each department may offer courses – Each department may have many ... a single department – Each student has an advisor

33

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

4

65

Developing an ER Diagram (continued)

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

4

66

Developing an ER Diagram (continued)

Page 34: Chapter 4 · • Each oval contains the name of ... – Each department may offer courses – Each department may have many ... a single department – Each student has an advisor

34

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

4

67

Database Design Challenges: Conflicting Goals

• Database design must conform to design standards

• High processing speeds are often a top priority in database design

• Quest for timely information might be focus of database design

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

4

68

Database Design Challenges: Conflicting Goals (continued)

Page 35: Chapter 4 · • Each oval contains the name of ... – Each department may offer courses – Each department may have many ... a single department – Each student has an advisor

35

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

4

69

Summary

• Entity relationship (ER) model

– Uses ERD to represent conceptual database

as viewed by end user

– ERM’s main components:

• Entities

• Relationships

• Attributes

– Includes connectivity and cardinality notations

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

4

70

Summary (continued)

• Connectivities and cardinalities are based on business rules

• In ERM, M:N relationship is valid at conceptual level

• ERDs may be based on many different ERMs

• Database designers are often forced to make design compromises