Normalize the table with many-many relationship

  • I need to create a table with many-many relationship. Could any one suggest me the way to do it.

  • Pls give more details.

    "Keep Trying"

  • Create a junction table having two columns(they are the primary keys in the two tables) as foreign keys to those tables.

  • A many-to-many relationship consists of three tables. Parent TableA, parent TableB, and the table that connects the two. This is not code, but describes the three tables:

    TableA

    TableAId int (PK)

    Desc nvarchar(50)

    UpdateDate... --whatever other columns

    TableB

    TableBId int (PK)

    Names nvarchar(75)

    CreateDate....--all the rest

    TableATableB

    TableAId (PK,FK)

    TableBId (PK,FK)

    Usually that's it for structure. Sometimes, if I were hanging another structure off the interim table, TableATableB, I might change the PK structure so that the FK's are just a unique constraint and some other column or columns define the PK... It all depends. But that's the basics.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • Any possibility of doing the same with only two tables but it should be normalized

  • For a many-to-many relationship... No. Not for a true one. Any relationship between two tables including referential integrity, can't allow for X number of relationships between the two.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply