Note that there are some explanatory texts on larger screens.

plurals
  1. POShould junction tables have more than one primary keys from another indentifying table?
    primarykey
    data
    text
    <p>Here's an exmaple: Originally I have 3 tables. Table B references Table A. So now Table B has two primary keys. One used as the original primary key and the other one to enforce its relationship with Tabe A. Then I want Table B to have a many-to-many relationship with Table X. As I'm adding the relationship, MySQL Workbench added Table Y with both of Table B primary keys and one primary key in Table X. So Table Y now has three primary keys.</p> <p>It seems like the second primary key from Table B in the junction table is unnecessary since I can identify Table B with the original primary key. So <strong>do I still need the extra primary key?</strong> Or perhaps I should not have an indetifying relationship between Table A and B?</p> <p>Table A and B have a relationship something like User has many Post. Post must belong to a User. But Post already has a primary key of its own, so <strong>does the foreign key to User need to be a primary key?</strong></p> <p><strong>EDIT</strong></p> <p>Here's the scenario (diagram link below). The tables I'm focusing on are snippet, snippet_topic and tag. From what I know, since every snippet must belong to a snippet_topic, it has an identifying relationship. So I used the identifying relationship in MySQL Workbench and they addded snippet_topic ID as a primary key. Afterwhich I added a m:n relationship for tag and snippet. MySQL Workbench added snippet_topic ID to the junction table (but I removed it). Is there anything wrong with my design? Or is there a more correct way to this?</p> <p>Legend: Yellow icon - primary key Red icon - not null <img src="https://i.stack.imgur.com/kBVt1.jpg" alt="Workbench EER Diagram"></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.
 

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