changed 4 years ago
Linked with GitHub
tags: Data Base

第九章: ER/EER Relational Mapping

ER 轉 Relational Mapping Algorithm

Step 1: Mapping of Regular Entity Types

  • 把 strong entity type E 變成 relation table R ,並包含所有 E 的 attributes
  • 選一個 key,若選到 composite attribute,則全部為 primary key

Step 2: Mappingg of Weak Entity Types

  • 把 weak entity type W 轉成 relation R 並且將 all attributes 包含於 R 中
  • 取 owner 的 primary key 當作 FK 放入 R 中
  • R 的 PK 是 FK + partial key

Step 3: Mapping of Binary 1:1 Relation Types

  • 3 種模式:
      1. Foreign Key approach:
      • 選一個有關係的 entity ,並把他的 PK 當成 FK include 進另一個 entity。(include 別人)的 entity 最好是 total 關係。
      1. Merged relation option:
      • 將兩個 entity 與之間的 relation 合併成一個表,適合於兩個 entity 都是 total
      1. Cross-reference or relationship relation option:
      • 建立新的表來代表 relation,使用兩方 entity 的 PK 來參考
  • 第一種

Step 4: Mapping of Binary 1:N Relationship Types

  • 把 1 的那方的 PK 當作 FK include 進另一個 entity 中
  • Include attribute 到 N 的 entity

Step 5: Mapping of Binary M:N Relationshop Types

  • 建立新的表代表 relationship ,包含兩方的 PK

Step 6: Mapping of Multivalued attributes

  • 建立新的表代表多值,並用 entity 的 PK 變成 FK 與多值組合成這個表的 PK

Step 7: Mapping of N-ary Rekationship Types

  • 當 N > 2,建立新的表來表示 relation ,並將多方 entity PK 包含進這個表

Step 8: Mapping Specialization or Generalization

  • 進行 specailization 與 generalized,有四個 options:

    • 8A(specialize): 每個 subclass/superclass 都建一個表,並將各個連接的 attribute 填入表中,另外,subclass 需 include superclass 的 PK 並成為 subclass 表的 PK

      Example

    • 8B(genralize): 每個 subclass 都建一個表,並將各個 attribute 填入表中,另外,subclass 們需要共有的 attributes 會填入 subclass 中,並找出一個共同的 PK

      Example

    • 8C(for disjoint specialize): 只建立一個 superclass 的表,並將各個 subclass 的 attribute 納入 superclass 的表中,另外,加上一個 type 的 attribute 來表示是哪個 subclass

    Example

    • 8D(for overlapping specialize): 只建立一個 superclass 的表,並加入 type 的 boolean 值,若為該 subclass ,則布林值為 true ,並在旁邊加上各個 subclass 的 attribute

      Example

    • 多重繼承狀況: 使用 8D 的狀況處理
      Example

Step 9: Mapping of Union Types

  • 建議 subclass 的表,並加入共同的 attributes
  • 定義一個新的 key attribute: 替代鍵
    Example: Registered_vehicle
Select a repo