Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>Originally I have 3 tables.</p> </blockquote> <p>Ok.</p> <blockquote> <p>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.</p> </blockquote> <p>No. Table B has one primary key and one foreign key. The foreign key might be part of the primary key, and it might not. </p> <blockquote> <p>Then I want Table B to have a many-to-many relationship with Table X.</p> </blockquote> <p>Ok.</p> <blockquote> <p>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> </blockquote> <p>A many-to-many relationship is typically implemented as a table that contains two foreign keys as its primary key. In your case, one foreign key is the primary key of Table B, and the other foreign key is the primary key of Table X. The primary key of Table B seems to contain two columns. The tables might look like this. </p> <ul> <li>Table A: {<strong>a<sub>1</sub></strong>, a<sub>2</sub>}</li> <li>Table B: {<strong>b<sub>1</sub>, a<sub>1</sub></strong>, b<sub>2</sub>, b<sub>3</sub>}, a<sub>1</sub> references Table A</li> <li>Table X: {<strong>x<sub>1</sub></strong>, x<sub>2</sub>}</li> </ul> <p>Table Y, which implements the m:n relationship, contains the keys from B and from X.</p> <ul> <li>Table Y: {<strong>b<sub>1</sub>, a<sub>1</sub>, x<sub>1</sub></strong>}, the two columns b<sub>1</sub>, a<sub>1</sub> reference Table B; the column x<sub>1</sub> references Table X</li> </ul> <p>If you want better answers, edit your question and include the SQL DDL for your tables. Get the DDL by using <a href="http://dev.mysql.com/doc/refman/5.0/en/show-create-table.html" rel="nofollow">SHOW CREATE TABLE</a>.</p>
    singulars
    1. This table or related slice is empty.
    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. 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