Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The technical definition of an identifying relationship is that a child's foreign key is part of its primary key.</p> <pre><code>CREATE TABLE AuthoredBook ( author_id INT NOT NULL, book_id INT NOT NULL, PRIMARY KEY (author_id, book_id), FOREIGN KEY (author_id) REFERENCES Authors(author_id), FOREIGN KEY (book_id) REFERENCES Books(book_id) ); </code></pre> <p>See? <code>book_id</code> is a foreign key, but it's also one of the columns in the primary key. So this table has an identifying relationship with the referenced table <code>Books</code>. Likewise it has an identifying relationship with <code>Authors</code>.</p> <p>A comment on a YouTube video has an identifying relationship with the respective video. The <code>video_id</code> <em>should</em> be part of the primary key of the <code>Comments</code> table.</p> <pre><code>CREATE TABLE Comments ( video_id INT NOT NULL, user_id INT NOT NULL, comment_dt DATETIME NOT NULL, PRIMARY KEY (video_id, user_id, comment_dt), FOREIGN KEY (video_id) REFERENCES Videos(video_id), FOREIGN KEY (user_id) REFERENCES Users(user_id) ); </code></pre> <p>It may be hard to understand this because it's such common practice these days to use only a serial surrogate key instead of a compound primary key:</p> <pre><code>CREATE TABLE Comments ( comment_id SERIAL PRIMARY KEY, video_id INT NOT NULL, user_id INT NOT NULL, comment_dt DATETIME NOT NULL, FOREIGN KEY (video_id) REFERENCES Videos(video_id), FOREIGN KEY (user_id) REFERENCES Users(user_id) ); </code></pre> <p>This can obscure cases where the tables have an identifying relationship.</p> <p>I would <em>not</em> consider SSN to represent an identifying relationship. Some people exist but do not have an SSN. Other people may file to get a new SSN. So the SSN is really just an attribute, not part of the person's primary key.</p> <hr> <p>Re comment from @Niels:</p> <blockquote> <p>So if we use a surrogate key instead of a compound primary key, there is no notable difference between use identifying or non-identifying relationship ?</p> </blockquote> <p>I suppose so. I hesitate to say yes, because we haven't changed the <em>logical</em> relationship between the tables by using a surrogate key. That is, you still can't make a Comment without referencing an existing Video. But that just means video_id must be NOT NULL. And the logical aspect is, to me, really the point about identifying relationships.</p> <p>But there's a physical aspect of identifying relationships as well. And that's the fact that the foreign key column is part of the primary key (the primary key is not necessarily a composite key, it could be a single column which is both the primary key of Comments as well as the foreign key to the Videos table, but that would mean you can store only one comment per video).</p> <p>Identifying relationships seem to be important only for the sake of entity-relationship diagramming, and this comes up in GUI data modeling tools.</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. 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