46
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 4 Entity Relationship (ER) Modeling

Database Systems: Design, Implementation, and Management Eighth Edition

  • Upload
    devon

  • View
    29

  • Download
    2

Embed Size (px)

DESCRIPTION

Database Systems: Design, Implementation, and Management Eighth Edition. Chapter 4 Entity Relationship (ER) Modeling. Objectives. In this chapter, you will learn: The main characteristics of entity relationship components - PowerPoint PPT Presentation

Citation preview

Page 1: Database Systems: Design, Implementation, and Management Eighth Edition

Database Systems: Design, Implementation, and

ManagementEighth Edition

Chapter 4Entity Relationship (ER) Modeling

Page 2: Database Systems: Design, Implementation, and Management Eighth Edition

Database Systems, 8th Edition 2

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

Page 3: Database Systems: Design, Implementation, and Management Eighth Edition

Database Systems, 8th Edition 3

4.1 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

Page 4: Database Systems: Design, Implementation, and Management Eighth Edition

Database Systems, 8th Edition 4

Entities

• Refers to entity set and not to single entity occurrence

• Corresponds to table and not to row in relational environment

• In Chen and Crow’s Foot models, entity represented by rectangle with entity’s name

• Entity name, a noun, written in capital letters (大寫 )

Page 5: Database Systems: Design, Implementation, and Management Eighth Edition

Database Systems, 8th Edition 5

Attributes

• Characteristics (特性 ) of entities• Chen notation: attributes represented by ovals

connected to entity rectangle with a line– Each oval contains the name of attribute it

represents

• Crow’s Foot notation: attributes written in attribute box below entity rectangle

Page 6: Database Systems: Design, Implementation, and Management Eighth Edition

Database Systems, 8th Edition 6

Page 7: Database Systems: Design, Implementation, and Management Eighth Edition

Database Systems, 8th Edition 7

Attributes (continued)

• Required (必要 ) attribute: must have a value, represented by bold font (粗體字 )

• Optional (選擇 ) attribute: may be left empty• Domain: set of possible values for an attribute

– Attributes may share a domain

• Identifiers(識別碼 ): one or more attributes that uniquely identify each entity instance

• Composite (組合 ) identifier: primary key composed of more than one attribute

Page 8: Database Systems: Design, Implementation, and Management Eighth Edition

Database Systems, 8th Edition 8

Page 9: Database Systems: Design, Implementation, and Management Eighth Edition

Database Systems, 8th Edition 9

Attributes (continued)

• Composite attribute (組合屬性 ) can be subdivided (分解 )

• Simple attribute cannot be subdivided• Single-value attribute can have only a single

value• Multi-valued attributes (多重數值屬性 ) can

have many values

Page 10: Database Systems: Design, Implementation, and Management Eighth Edition

Database Systems, 8th Edition 10

Page 11: Database Systems: Design, Implementation, and Management Eighth Edition

Database Systems, 8th Edition 11

Attributes (continued)

• M:N relationships and multi-valued attributes should not be implemented

– Create several new attributes for each of the original multi-valued attributes components

– Create new entity composed of original multi-valued attributes components

• Derived (衍生 ) attribute: value may be calculated from other attributes– Need not be physically stored within database

Page 12: Database Systems: Design, Implementation, and Management Eighth Edition

Database Systems, 8th Edition 12

Page 13: Database Systems: Design, Implementation, and Management Eighth Edition

Database Systems, 8th Edition 13

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 or 1:1• Relationship classification is difficult to establish

if only one side of the relationship is known

Page 14: Database Systems: Design, Implementation, and Management Eighth Edition

Database Systems, 8th Edition 14

Connectivity and Cardinality

• Connectivity (連接性 )– Describes the relationship classification as 1-to-1,

1-to-many, or many-to-many

• Cardinality (基數 )– Expresses minimum and maximum number of

entity occurrences associated with one occurrence of related entity using the format (x, y)

• Established by very concise statements known as business rules

Page 15: Database Systems: Design, Implementation, and Management Eighth Edition

Database Systems, 8th Edition 15

Page 16: Database Systems: Design, Implementation, and Management Eighth Edition

Database Systems, 8th Edition 16

Existence Dependence

• Existence dependence (存在相依 )– Entity exists 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 such an entity is referred to as a

strong or regular entity

Page 17: Database Systems: Design, Implementation, and Management Eighth Edition

Database Systems, 8th Edition 17

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 18: Database Systems: Design, Implementation, and Management Eighth Edition

18Fig 4.8 A weak relationship between COURSE and CLASS

虛線

Page 19: Database Systems: Design, Implementation, and Management Eighth Edition

19Fig 4.9 A strong relationship between COURSE and CLASS

實線

Page 20: Database Systems: Design, Implementation, and Management Eighth Edition

Database Systems, 8th Edition 20

Weak Entities

• Weak entity (弱實體 ) meets two conditions– Existence-dependent

– Primary key partially or totally derived from parent entity in relationship

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

Page 21: Database Systems: Design, Implementation, and Management Eighth Edition

21Fig 4.10 A weak entity in an ERD

實線

Page 22: Database Systems: Design, Implementation, and Management Eighth Edition

22Fig 4.11 A weak entity in a strong relationship

Page 23: Database Systems: Design, Implementation, and Management Eighth Edition

Database Systems, 8th Edition 23

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

Page 24: Database Systems: Design, Implementation, and Management Eighth Edition

24

Page 25: Database Systems: Design, Implementation, and Management Eighth Edition

Database Systems, 8th Edition 25

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 26: Database Systems: Design, Implementation, and Management Eighth Edition

Database Systems, 8th Edition 26

Page 27: Database Systems: Design, Implementation, and Management Eighth Edition

Fig 4.16 The implementation of a ternary relationship27

Page 28: Database Systems: Design, Implementation, and Management Eighth Edition

Database Systems, 8th Edition 28

Recursive (遞迴 ) Relationships

• Relationship can exist between occurrences of the same entity set– Naturally found within unary relationship

Page 29: Database Systems: Design, Implementation, and Management Eighth Edition

Fig 4.20 Implementation of the M:N recursive “PART contains PART” relationship29

Page 30: Database Systems: Design, Implementation, and Management Eighth Edition

Database Systems, 8th Edition 30

Page 31: Database Systems: Design, Implementation, and Management Eighth Edition

Database Systems, 8th Edition 31

Associative (Composite) Entities (關聯實體、組合實體 )

• Also known as bridge entities (橋接實體 )• Used to implement M:N relationships• 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 32: Database Systems: Design, Implementation, and Management Eighth Edition

Database Systems, 8th Edition 32

Page 33: Database Systems: Design, Implementation, and Management Eighth Edition

Database Systems, 8th Edition 33

Page 34: Database Systems: Design, Implementation, and Management Eighth Edition

Database Systems, 8th Edition 34

4.2 Developing an ER Diagram

• Database design is an iterative process (反覆式流程 )

– 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

Page 35: Database Systems: Design, Implementation, and Management Eighth Edition

Database Systems, 8th Edition 35

Page 36: Database Systems: Design, Implementation, and Management Eighth Edition

Database Systems, 8th Edition 36

Page 37: Database Systems: Design, Implementation, and Management Eighth Edition

Database Systems, 8th Edition 37

Page 38: Database Systems: Design, Implementation, and Management Eighth Edition

Database Systems, 8th Edition 38

Page 39: Database Systems: Design, Implementation, and Management Eighth Edition

Database Systems, 8th Edition 39

Page 40: Database Systems: Design, Implementation, and Management Eighth Edition

Database Systems, 8th Edition 40

Page 41: Database Systems: Design, Implementation, and Management Eighth Edition

Fig 4.36 The conceptual UML class diagram for Tiny College 41

Page 42: Database Systems: Design, Implementation, and Management Eighth Edition

42Fig 4.37 The implementation-ready UML class diagram for Tiny College

Page 43: Database Systems: Design, Implementation, and Management Eighth Edition

Database Systems, 8th Edition 43

4.3 Database Design Challenges: Conflicting Goals

• Database designers must make design compromises– Conflicting goals: design standards, processing

speed, information requirements• Important to meet logical requirements and

design conventions (慣例 )• Design of little value unless it delivers all

specified query and reporting requirements• Some design and implementation problems do

not yield “clean” solutions

Page 44: Database Systems: Design, Implementation, and Management Eighth Edition

44Fig 4.38 Various Implementation of the 1:1 recursive relationship

Page 45: Database Systems: Design, Implementation, and Management Eighth Edition

Database Systems, 8th Edition 45

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

Page 46: Database Systems: Design, Implementation, and Management Eighth Edition

Database Systems, 8th Edition 46

Summary (continued)

• Connectivities and cardinalities are based on business rules

• M:N relationship is valid at conceptual level– Must be mapped to a set of 1:M relationships

• ERDs may be based on many different ERMs• Database designers are often forced to make

design compromises