Many-to-many relations?

Discussion of open issues, suggestions and bugs regarding database management and administration tools for MySQL
Post Reply
solmyr72
Posts: 2
Joined: Sat 13 Feb 2010 13:29

Many-to-many relations?

Post by solmyr72 » Sat 13 Feb 2010 13:43

Hi,

I'm using Dbforge Studio for MySQL (Express edition).

In a "Database Diagram", how do I define a many-to-many relation?

In my Diagram, I defined 2 tables: "Customer" and "Supplier".
Now I want a many-to-many relation between them (through some junction table, say we call it "CustSupplier", which contains only the required foreign keys).

Would anyone be kind enough to tell me what to do, exactly?
I tried "New Relation", but it seems to assume I want "one-to-many"....

Thanks very much :)

.jp
Devart Team
Posts: 345
Joined: Wed 09 Sep 2009 06:55
Location: devart

Post by .jp » Mon 15 Feb 2010 10:39

Many-to-many relationships between tables are accommodated in databases by means of junction tables. A junction table contains the primary key columns of the two tables you want to relate.

To create a many-to-many relationship between tables in dbForge Studio for MySQL:

1. Create/Open a database diagram.

2. Add the tables that you want to create a many-to-many relationship between.

3. Create a third table by right-clicking within the database diagram, and then clicking New Table.
This will become the junction table.

4. In the table editor's dialog box, enter a name for the table.
For example, the junction table between the Customer table and the Supplier table is named CustomerSupplier.

5. Copy the primary key columns from each of the other two tables to the junction table.
You can add other columns to this table, just as you can to any other table.

6. In the junction table, set the primary key to include all the primary key columns from the other two tables.

7. Define a one-to-many relationship between each of the two primary tables and the junction table.

Note: The creation of a junction table in a database diagram does not insert data from the related tables into the junction table. You can copy rows from one table to another or within a table using an Insert From query.

solmyr72
Posts: 2
Joined: Sat 13 Feb 2010 13:29

Post by solmyr72 » Tue 16 Feb 2010 08:46

.jp wrote:Many-to-many relationships between tables are accommodated in databases by means of junction tables. A junction table contains the primary key columns of the two tables you want to relate.

To create a many-to-many relationship between tables in dbForge Studio for MySQL...:
Thanks very much for this detailed reply.

Post Reply