How to to create a many-to-many relationship between tables in SQL Server database

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

To create a many-to-many relationship between tables in dbForge Studio for SQL Server you need to:

  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 a 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.

  1. In the junction table, set the primary key to include all primary key columns from the other two tables.
  2. 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.

With dbForge Studio for SQL Server, you can create a many-to-many relationship between tables in a database quickly and easily.

Download dbForge Studio for SQL Server and try it absolutely free for 30 days!

Want to Find out More?

Overview

Overview

Take a quick tour to learn all about the key benefits delivered by dbForge Studio for SQL Server.
All Features

All features

Get acquainted with the rich features and capabilities of the Studio in less than 5 minutes.
Request a demo

Request a demo

If you consider employing the Studio for your business, request a demo to see it in action.
Ready to start using dbForge Studio for SQL Server?