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
    In the case of many students taking many courses this is a many to many relationship, please correct your question
    – bikeman868
    Commented Apr 12, 2018 at 6:02

1 Answer 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 you have read our privacy policy.

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