HackMD
  • Beta
    Beta  Get a sneak peek of HackMD’s new design
    Turn on the feature preview and give us feedback.
    Go → Got it
      • Create new note
      • Create a note from template
    • Beta  Get a sneak peek of HackMD’s new design
      Beta  Get a sneak peek of HackMD’s new design
      Turn on the feature preview and give us feedback.
      Go → Got it
      • Sharing Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • More (Comment, Invitee)
      • Publishing
        Please check the box to agree to the Community Guidelines.
        Everyone on the web can find and read all notes of this public team.
        After the note is published, everyone on the web can find and read this note.
        See all published notes on profile page.
      • Commenting Enable
        Disabled Forbidden Owners Signed-in users Everyone
      • Permission
        • Forbidden
        • Owners
        • Signed-in users
        • Everyone
      • Invitee
      • No invitee
      • Options
      • Versions and GitHub Sync
      • Transfer ownership
      • Delete this note
      • Template
      • Save as template
      • Insert from template
      • Export
      • Dropbox
      • Google Drive Export to Google Drive
      • Gist
      • Import
      • Dropbox
      • Google Drive Import from Google Drive
      • Gist
      • Clipboard
      • Download
      • Markdown
      • HTML
      • Raw HTML
    Menu Sharing Create Help
    Create Create new note Create a note from template
    Menu
    Options
    Versions and GitHub Sync Transfer ownership Delete this note
    Export
    Dropbox Google Drive Export to Google Drive Gist
    Import
    Dropbox Google Drive Import from Google Drive Gist Clipboard
    Download
    Markdown HTML Raw HTML
    Back
    Sharing
    Sharing Link copied
    /edit
    View mode
    • Edit mode
    • View mode
    • Book mode
    • Slide mode
    Edit mode View mode Book mode Slide mode
    Note Permission
    Read
    Only me
    • Only me
    • Signed-in users
    • Everyone
    Only me Signed-in users Everyone
    Write
    Only me
    • Only me
    • Signed-in users
    • Everyone
    Only me Signed-in users Everyone
    More (Comment, Invitee)
    Publishing
    Please check the box to agree to the Community Guidelines.
    Everyone on the web can find and read all notes of this public team.
    After the note is published, everyone on the web can find and read this note.
    See all published notes on profile page.
    More (Comment, Invitee)
    Commenting Enable
    Disabled Forbidden Owners Signed-in users Everyone
    Permission
    Owners
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Invitee
    No invitee
       owned this note    owned this note      
    Published Linked with GitHub
    Like BookmarkBookmarked
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    ###### tags: `Data Base` # 第七章: Entity-Relationship(ER) Model ![](https://i.imgur.com/7NkCBbS.png) ![](https://i.imgur.com/G2B2JvH.png) 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: ![](https://i.imgur.com/7CodGA5.png) ## 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 有關係 - ![](https://i.imgur.com/nh4Jcpr.png) ## 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\}$ <br/> 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 ![](https://i.imgur.com/buBjpWb.png) ![](https://i.imgur.com/wQNBSEw.png) ![](https://i.imgur.com/naMUXKC.png) ## Alternative (min, max) Notation - min: 最少幾個 instance 有關係 - max: 最多幾個 instance 有關係 ![](https://i.imgur.com/CZSBg9K.png) ![](https://i.imgur.com/xdRPmDj.png) ## 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 組合起來) ![](https://i.imgur.com/xH8obVu.png) ## Other Alternative Diagrammatic Notations ![](https://i.imgur.com/WNigFDk.png) ## Ternary Relationship ![](https://i.imgur.com/I3MFsbw.png) ![](https://i.imgur.com/Edt5uxh.png) - 如果 binary relation 可以被 ternary relation 推導,那就是多餘的 ![](https://i.imgur.com/XDKclAK.png)

    Import from clipboard

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lost their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template is not available.


    Upgrade

    All
    • All
    • Team
    No template found.

    Create custom template


    Upgrade

    Delete template

    Do you really want to delete this template?

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Tutorials

    Book Mode Tutorial

    Slide Mode Tutorial

    YAML Metadata

    Contacts

    Facebook

    Twitter

    Feedback

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions

    Versions and GitHub Sync

    Sign in to link this note to GitHub Learn more
    This note is not linked with GitHub Learn more
     
    Add badge Pull Push GitHub Link Settings
    Upgrade now

    Version named by    

    More Less
    • Edit
    • Delete

    Note content is identical to the latest version.
    Compare with
      Choose a version
      No search result
      Version not found

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub

        Please sign in to GitHub and install the HackMD app on your GitHub repo. Learn more

         Sign in to GitHub

        HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Available push count

        Upgrade

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Upgrade

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully