Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy is the foreign key part of the primary key in an identifying relationship?
    primarykey
    data
    text
    <p>OK, I hope this is an appropriate question for stackoverflow as I'm trying to understand a concept rather than fixing a piece of code that won't work.</p> <p>I'll take a general example of a <strong>form</strong> (parent table) and a <strong>form field</strong> (child table). <strong>Logically</strong>, this would be an identifying relationship, since a form field cannot exist without a form.</p> <p><img src="https://i.stack.imgur.com/CaC1h.png" alt="form and form_field tables"></p> <p>This would make me think that in order to translate the <strong>logical</strong> relationship into the <strong>technical</strong> relationship, a simple <code>NOT NULL</code> for the form_id field in the form_field table would suffice. (see the left part of above screenshot)</p> <p>However, when I add an identifying relationship using MySQL Workbench, form_id is not only <code>NOT NULL</code> but also part of the primary key. (see the right part of above screenshot)<br> And when I add a non-identifying relationship, <code>NOT NULL</code> is still applied so logically it would actually be an identifying relationship as well.</p> <p>I guess this confuses me a little, as well as the fact that until now I always simply used the id field as primary key.</p> <p>So I understand the <strong>logical</strong> concept of identifying vs. non-identifying relationships, but I don't understand the <strong>technical</strong> part. Why is it, as <a href="https://stackoverflow.com/a/762994/1001110">this answer</a> states, 'the "right" way to make the foreign key part of the child's primary key'? What is the benefit of these composite primary keys?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    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