What's the difference between identifying and non-identifying relationships?

前端 未结 15 1801
迷失自我
迷失自我 2020-11-22 12:02

I haven\'t been able to fully grasp the differences. Can you describe both concepts and use real world examples?

15条回答
  •  余生分开走
    2020-11-22 12:21

    Here's a good description:

    Relationships between two entities may be classified as being either "identifying" or "non-identifying". Identifying relationships exist when the primary key of the parent entity is included in the primary key of the child entity. On the other hand, a non-identifying relationship exists when the primary key of the parent entity is included in the child entity but not as part of the child entity's primary key. In addition, non-identifying relationships may be further classified as being either "mandatory" or "non-mandatory". A mandatory non-identifying relationship exists when the value in the child table cannot be null. On the other hand, a non-mandatory non-identifying relationship exists when the value in the child table can be null.

    http://www.sqlteam.com/article/database-design-and-modeling-fundamentals

    Here's a simple example of an identifying relationship:

    Parent
    ------
    ID (PK)
    Name
    
    Child
    -----
    ID (PK)
    ParentID (PK, FK to Parent.ID) -- notice PK
    Name
    

    Here's a corresponding non-identifying relationship:

    Parent
    ------
    ID (PK)
    Name
    
    Child
    -----
    ID (PK)
    ParentID (FK to Parent.ID) -- notice no PK
    Name
    

提交回复
热议问题