Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A child table (A.K.A. <a href="http://en.wikipedia.org/wiki/Weak_entity" rel="noreferrer">weak entity</a>) is a table whose primary key attributes <strong><em>depend</em></strong> on another table, thus the child table is <em>identified</em> or <em>partially identified</em> by rows in the table it depends on (parent). Rows in a child table cannot exist without a corresponding row in its parent table. </p> <p>To illustrate, let's take a simple and completely relevant example we are all familiar with: <em>Parents and children in the context of family</em>. We can model out this relationship with tables like so:</p> <p><img src="https://i.stack.imgur.com/guJAB.jpg" alt="Parent to Child Identifying Relationship"></p> <p>In the model above, each row in the <code>Parents</code> table is <strong><em>uniquely identified</em></strong> by an <code>SSN</code>. The <code>SSN</code> is an intrinsic and unique attribute to each parent, thus it is a standalone or "strong" entity because it does not rely on another table to define its identity.</p> <p>Children however, <em>require</em> a parent in order to exist (<code>Parent_SSN</code> <strong><em>must</em></strong> reference to an existing <code>SSN</code> in the <code>Parents</code> table). </p> <p>Notice the composite primary key (<code>Parent_SSN, Name</code>) in the <code>Children</code> table. This means that children are <strong><em>uniquely identified</em></strong> by the <em>combination</em> of <code>Parent_SSN</code> <strong>and</strong> <code>Name</code>. You cannot query for an individual child based only on the <code>Name</code> field because multiple parents may have children with the same name. Likewise, you cannot query for an individual child based only on the <code>Parent_SSN</code> field because one parent may have many children. Taking that into consideration, children are partially identified by their parent, hence <strong><em>identifying</em></strong> relationship.</p> <p>But can't children be uniquely identified by an SSN as well? Why yes, certainly. Let's go ahead and adjust our model to include that:</p> <p><img src="https://i.stack.imgur.com/JUcIa.jpg" alt="Parent to Child Non-Identifying Relationship"></p> <p>In this version of the model, notice we have introduced the <code>SSN</code> field for <code>Children</code>. The <strong>unique identity</strong> of children is now defined by their own intrinsic and unique <code>SSN</code>. Their identity <strong>no longer depends</strong> on the <code>Parents</code> table. Although the <code>Parent_SSN</code> field still references the <code>SSN</code> of the <code>Parents</code> table, it has no part in the <em>unique identity</em> of the child, thus parents have a <strong><em>non-identifying</em></strong> relationship to their children, and both tables can now be considered "strong" standalone entities.</p> <p>As an aside, this version of the model has a few advantages over the first:</p> <ul> <li>One parent may now have two or more children with the same name, whereas the <a href="http://en.wikipedia.org/wiki/Entity_integrity" rel="noreferrer">entity integrity</a> constraint in the previous model would not allow for this.</li> <li>You can allow the <code>Parent_SSN</code> field to contain <code>NULL</code> to account for the event that you have data about the child, but do not know who his/her parent is.</li> </ul> <p>In both of the above models, the <code>Parents</code> table is considered to be the parent table of the <code>Children</code> table. However, in <strong>non-identifying</strong> relationships like in the second model, <code>Parents</code> is only a parent table in the context of the foreign key <code>Parent_SSN</code> because <code>Parent_SSN</code> <em>references/depends</em> on <code>SSN</code> in the <code>Parents</code> table, but <em>does not</em> have any part in defining the actual identity of children.</p> <p>To illustrate why context is important when deciding which tables are parent/child tables, consider the following example involving a circular dependency:</p> <p><img src="https://i.stack.imgur.com/4QAHu.jpg" alt="Employee Department Relationships"></p> <p>In this example, employees and departments are uniquely identified by their own attributes and do not derive any part of their identity from other tables.</p> <p>Here, we have two non-identifying relationships: an employee works for a department (<code>DeptNo</code> in the <code>Employee</code> table), and a department is managed by an employee (<code>ManagerSSN</code> in the <code>Department</code> table). Which one is the parent table? ...Child table?</p> <p>It depends on context — which foreign key relationship are you talking about? The Department table would be considered the parent table in the context of <code>DeptNo</code> in the <code>Employee</code> table because <code>DeptNo</code> is <em>referencing/dependent</em> on the <code>Department</code> table. </p> <p>However, the Employee table would be considered the parent table in the context of <code>ManagerSSN</code> in the <code>Department</code> table because <code>ManagerSSN</code> is <em>referencing/dependent</em> on the <code>Employee</code> table.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload