Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Many-to-Many Relation

 
JiaPei Jen
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do I prepare my database to handle many-to-many relation?
 
Wayne L Johnson
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps the most common method is to create a third table where you store foreign keys into the two tables in the relationship. So if you have STUDENT and CLASS tables, and you want to manage them in a many-to-many relationship, do something like this:

You could add a primary key to the "STUDENT_CLASS" key that is separate from the StudentID/ClassID combination, and possibly have other information (DateCreated, etc). But using a join table like this is the most common approach.
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!