changed 4 years ago
Linked with GitHub
tags: Data Base

第七章: Entity-Relationship(ER) Model


  1. 先設計 ER-model
  2. 轉換 relational schema
  3. Normalization

Type of Attibutes

  • Simple: atomic value
  • Composite: 組合值,ex: Name(FirstName, MiddleName, LastName)
  • Muti-valued: 多個值,ex: Color{blue, red, gray}
  • Derived attributes: 推導的值,ex: Age, date of birth
  • Complex attributes: 結構複雜的值

Entity

  • 具有相同 attribute 但有 unique value 的 set,稱為 Entity set

Entity Types and Key Attributes

  • Key attribute may be composite,ex: (Number, State)
  • Key 可能有多個

Keys

  • Multivalued attributes - 雙橢圓
  • Composite attributes - Attribute 再延伸
    • EX:

Rekationships and Relationship Types

  • Relation 的 degree - 有多少個 entity 參與 relation

  • Relationship Type 指的是 relation 的 datatype

  • Relationship Set 指的是 relation 的 instance

Recursive Relationship Type

  • 同個 entity 有對自己的關係,ex: employee 中有 supervisor role,會對同樣是 employee 的 instance 有關係

Contraints on Relationship Types

  • Cardinality Ratio

    • One-to-one(1:1)
    • One-to-many(1:N)
    • Many-to-many(M:N)
  • Existence Dependarncy: 限定最小要多少 enitity 加入 relation

  • Participation constraint:

    • Total: 所有 instance 都要有關係
    • Partial: 不用所有 instance 都要有關係

Attributes of Relationship Types

  • 1:1 - 可以把 relation attribute 轉移至 enetity 上
  • 1:N - 可以把 relation attribute 轉移到 N-side 的 entity 上
  • M:N
    • 有些 attribute 會是組合的 participateing entity
    • 必須在 relationship 上,不能轉移

Relationships

定義: \(\{(e_1,e_2,...,e_n)|e_1 \in E_1,...,e_n \in E_n\}\)
where (e_1,e_2, e_n) is relationship
ex: (JohnPharmacy) \(\in\) Works_in

Weak Entity Types

  • 沒有 key attribute
  • weak entity 要附在有 entity 的 relationship type 上
  • 限制:
    • weak key = strong entity key + partial entity key
    • Weak entity 需要跟 其他 entity 有關
  • 永遠是 Total participation

Summary of Notation for ER Diagrams



Alternative (min, max) Notation

  • min: 最少幾個 instance 有關係
  • max: 最多幾個 instance 有關係

UML Class Diagrams

  • Top section: entity type(class) name
  • Middle section: attributes
  • Last section: class operations(方法)

Relation

  • Binary association:

    • Line connecting participating class
    • 可以取名
  • Link attribute: 將 attribute 放入 box 中,用虛線連接

  • Multiplicities: min..max, 星號(*) 表示不限 participations

  • 有兩種 relationships:

    • association: 普通實線,表示有被指向的 class
    • aggregation: 線上有空心菱形,有菱形的那方擁有沒有菱形的那方(擁有許多部分 class 組合起來)

Other Alternative Diagrammatic Notations

Ternary Relationship


  • 如果 binary relation 可以被 ternary relation 推導,那就是多餘的

Select a repo