1

What is the best approach to mapping between two tables with many to many relationship? Is it best to create third table with id of each table as foreign key ? For example student table and course table each student have many courses.

1
  • 1
    In the case of many students taking many courses this is a many to many relationship, please correct your question
    – bikeman868
    Apr 12, 2018 at 6:02

1 Answer 1

1

An intersection table such as you've described is the standard way to implement a many to many relationship in a physical relational database.

The intersection table has foreign keys to each of the parent tables that it's joining. These may be simple or compound foreign keys. That doesn't matter.

The primary key of the intersection table is the combination of the two foreign keys to the parent tables. For this reason, the primary key of an intersection table is always a compound foreign key.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.