Presentation is loading. Please wait.

Presentation is loading. Please wait.

5 Copyright © 2006, Oracle. All rights reserved. Understanding Entity Relationship Diagrams ( 實體關係圖 ) Part I.

Similar presentations


Presentation on theme: "5 Copyright © 2006, Oracle. All rights reserved. Understanding Entity Relationship Diagrams ( 實體關係圖 ) Part I."— Presentation transcript:

1 5 Copyright © 2006, Oracle. All rights reserved. Understanding Entity Relationship Diagrams ( 實體關係圖 ) Part I

2 5.1 - 2 Outline Notation ( 表示法 ) of Entity Relationship Diagram More Aspects of Relationships Generalization hierarchies ( 歸納類別的階層架構 ) Business rule ( 企業規則 ) representation Diagram rules ( 圖形規則 ) Alternative notations

3 5.1 - 3 Importance of Database Relationship Diagram

4 5.1 - 4 Basic Elements and Symbols of Entity-Relationship Diagram (ERD) ERDs have three basic elements: Entity type ( 實體類別 ) relationship ( 關係 ) attribute ( 屬性 )

5 5.1 - 5 Entity Type ( 實體類別 ) A collection of entities (persons, places, events, or things) of interest An entity is a member or instance ( 實例 ) of an entity type. Entities are uniquely identified to allow tracking across business processes. Represented by a rectangle

6 5.1 - 6 Relationship ( 關係 ) A named association among entity types. A relationship represents a two-way or bidirectional association among entities. Most relationships involve two distinct entity types. Course Has Offerings (a verb usually)

7 5.1 - 7 Attribute ( 屬性 ) A property of an entity type or relationship. Each attribute has a data type which defines the kind of values and permissible operations on the attribute. Underline(s) indicates that the attribute(s) serves as the primary key of the entity type.

8 5.1 - 8 Interpretation of ER Diagram ( ERD, 實體關係圖) ERD has a natural language correspondence. entity types : nouns, relationship : verb/prepositional phrase Interpretation of a relationship can be bidirectional. It can be used to navigate in both directions – From Course to Offering : Has, Provides – From Offering to Course : IsProvidedFor Which word to use for naming a relationship? Try to use active verb; not always possible

9 5.1 - 9 Relationship Cardinality Cardinality ( 基數 ) A constraint on the number of entities that participate in a relationship. In an ERD, the minimum and maximum cardinalities are specified for both directions of a relationship.

10 5.1 - 10 Instance Diagram ( 實例圖 ) Useful to understand relationship cardinality Lines show connections among entities –Course1 is related to Offering1, Offering2, and Offering3 –Course2 is related to Offering4 –Course3 is not related to any offerings An example of instance diagram

11 5.1 - 11 Example of Relationship Cardinality in Instance Diagram An example : Each course is related to a minimum of 0 and maximum of many offerings –Course1 is related to 3 offerings –Course2 is related to 1 offering –Course3 is related to 0 offering Each offering is related to exactly one course

12 5.1 - 12 Cardinality Representation in ER Diagram (Crow’s Foot ( 烏鴉腳 ) Notation) - Course is related to a min of 0 and max of many offerings - Offering is related to a min of 1 and max of 1 courses (exactly one)

13 5.1 - 13 Classification of Relationship by Relationship Cardinalities Minimum cardinality based Mandatory ( 強制 ) relationship: Minimum cardinality  1 Optional ( 非必要 ) relationship: Minimum cardinality = 0 Maximum cardinality based Functional ( 函數性的 ) or Single-valued( 單值的 ) relationship: Maximum cardinality = 1 1-M relationship: Maximum cardinality = 1 in one direction and maximum cardinality > 1 in the other direction. M-N relationship: Maximum cardinality is > 1 in both directions. 1-1 relationship: Maximum cardinality = 1 in both directions.

14 5.1 - 14 Summary of Relationship Classification by Relationship Cardinalities Relationship Classification Cardinality Restrictions Mandatory Minimum cardinality  1 (at one end) OptionalMinimum cardinality = 0 (at one end) Functional or single-valued Maximum cardinality = 1 (at one end) 1-M (1 對多 ) Maximum cardinality = 1 in one direction and maximum cardinality > 1 in the other direction. M-N ( 多對多 ) Maximum cardinality is > 1 in both directions. 1-1 (1 對 1) Maximum cardinality = 1 in both directions.

15 5.1 - 15 Existence Dependency ( 存在的依賴 ) An entity that cannot exist unless another related entity exists. A mandatory relationship ( 強制式的關係 ) creates an existence dependency Example: The Offering entity type depends on the Has relationship

16 5.1 - 16 Example of Relationship Classification Has relationship is optional to the Course entity type. A Course entity can be stored without being related to an Offering entity. Has relationship is mandatory to the Offering entity type. An Offering entity cannot be stored without a related Course entity.

17 5.1 - 17 More Examples on Relationship Classification 1-1 and M-N Relationship Examples 1-1: Maximum cardinality = 1 in both directions. M-N: Maximum cardinality is > 1 in both directions.

18 5.1 - 18 ER Diagram vs. Access Relational Diagram ER Diagram Access Relational Diagram Doesn’t show minimum cardinality

19 5.1 - 19 Differences Between ERD & Relational Database Diagram 1.No relationship name in relational database diagram ( Instead FKs represent relationships). ERD notation does not use FKs 2.Relational database diagram shows only maximum cardinalities 3.Relational database diagram allow a relationship between two tables only. Some ERD notations allow M-way relationship ( 多方的關係 ). 4.Relationship with attributes is not permitted in the relational database diagram

20 5.1 - 20 More Aspects of Relationships on ERD Notation Identification dependency ( 識別的依賴 ) Weak Entities ( 弱實體類別 ) Identifying Relationships ( 識別關係 ) More Relationship Patterns ( 關係樣式 ) M-N Relationships with Attributes (An M-N Relationship is implemented as a table in a D/B) Self-Referencing (Unary) Relationships M-way relationships ( 多方的關係 ) Equivalence between M-N and 1-M relationships   

21 5.1 - 21 Identification Dependency ( 識別的依賴 ) Identification dependency is a specialized kind of existence dependency (with minimum cardinality of 1). Weak Entity ( 弱實體類別 ) –An entity type that borrows part or entire of its PK from other entity types –Its unique identification depends on an identifying relationship Identifying relationship ( 識別關係 ) –An identifying relationship creates an identification dependency –Indicates the source of borrowed PK of a weak entity

22 5.1 - 22 Identification Dependency Identification dependency involves a weak entity and one or more identifying relationship. Example: Identification Dependency Symbols: Solid relationship line for identifying relationships Diagonal lines in the corners denote weak entities. The PK of Room is a a composite PK. It is combined from RoomNo (local part of its PK) BldgID (borrowed part of its PK) Local Key or Partial PK

23 5.1 - 23 Identification Dependency A specialized kind of existence dependency (a mandatory relationship with minimum cardinality of 1 ) The unique identification of Weak entity depends on an identifying relationship The minimum and maximum cardinalities of a weak entity are always 1.

24 5.1 - 24 More Relationship Patterns( 樣式 ) M-N Relationships with Attributes Self-Referencing (Unary) Relationships Associative entity types ( 組合的實體類別 ) representing M-way relationships ( 多方關係 )

25 5.1 - 25 M-N Relationships with Attributes Relationships can have attributes just like entity types Very typical for M-N relationships Attribute depends on both entity types, not just one of the entity types EnrGrade is an attribute of the M-N relationship Enrollsln

26 5.1 - 26 M-N Relationships with Attributes Grade recorded for a student in a particular course offering Depends on the combination of Student and Offering EnrGrade is not part of the Student or Offering entity types

27 5.1 - 27 Self-Referencing Relationships ( 自我參照關係 ) Involves connections among members of the same entity type Example: –Employees: supervisory ( 管理的 ) relationships –Courses: prerequisite ( 先修課 ) structures

28 5.1 - 28 Self-Referencing Relationships Instance Diagrams (實例圖 ) ERD 1 個直接上司 2 個直接下屬 1 個直接上司 0 個直接下屬 0 個 直接 上司 2 個直接下屬 直接下屬最少 0 個 直接下屬最多 2 個 直接 上司最少 0 個 直接 上司最多 1 個

29 5.1 - 29 ERD Notation for Self-Referencing Relationships Instance Diagrams (實例圖 ) ERD 1 門先修 擋修 1 門 1 門先修 擋修 2 門 0 門先修 擋修 1 門 2 門先修 擋修 0 門 先修最少 0 門,最多 2 門 擋修最少 0 門,最多 2 門

30 5.1 - 30 Associative Entity Types ( 組合的實體類別 ) for M-way Relationships M-way Relationships ( 多方的關係 ) –Relationships involve more than 2 entity types Notation Example: The Chen Notation A 3-way relationship ( 三方的關係 ) tracks which supplier supplies a part on a specified project The Chen Notation

31 5.1 - 31 Associative Entity Types for M-way Relationships Crow's Foot notation does not directly (but indirectly) support M-way relationships –Use an associative entity type and a collection of identifying 1-M relationships to represent an M-way relationship Associative entity type –A weak entity that depends on two or more entity types for its PK — Usually borrows entire PKs from related entity types –A replacement for M-N or M-way relationship

32 5.1 - 32 Associative Entity Types for 3-way Relationships Associative entity type The Crow’s Foot Notation that represents a ternary relationship

33 5.1 - 33 Equivalence Between M-N & 1-M Relationships An M-N relationship can be replaced by –An associative entity type and –Two identifying 1-M relationships (1 對多的辨識關係 ) Enrollment entity type –Weak entity –PK: Combination of StdSSN and OfferNo

34 5.1 - 34 Flexible Associative Entity Type M-N relationship versus associative entity type M-N relationship is preferred (more concise) in most cases. But, associative entity type is more flexible in some situations, e.g. when an M-N relationship must have a relationship with other entity type. An example : Attendance entity type relates to Enrollment –Weak entity (related to Enrollment ‘relationship’) –PK: Combination of AttDate and PK of Enrollment

35 5.1 - 35 自我練習 HW 第五章 160 頁 Questions : 5, 7, 8, 11, 15, 16, 17, 18, 19


Download ppt "5 Copyright © 2006, Oracle. All rights reserved. Understanding Entity Relationship Diagrams ( 實體關係圖 ) Part I."

Similar presentations


Ads by Google