Jump to content
xisto Community
Sign in to follow this  
.hack//GU

Problem To Join Tables In Database Problem in joining (many to many) relation

Recommended Posts

Please help me. I'm building a group of database fro a program.the situation is like this: 'user' may have 1 or more class(es). 'class' itself may have 1 or more user in its classroom.I'm bad at explaining... maybe like this: A program is made to write data of classroom. Hikaru has a math class at Monday and statistic class at Tuesday. The math class itself consists of about 50 students in a classroom.So, Hikaru (user ) may have one or more class at time,math class (class) may have one or more students at time.So, basically I must make these two tables joined together. It is (many-to-many) relation in which I haven't known how to build. So, please tell me how I build these two tables.Thanks in advance.

Share this post


Link to post
Share on other sites

Hi, your best option is to add the third table to handle the many to many relationships.

You have basically two options, first is allowing multiple identical links. In that case you should have three fields in the table, numerical primary key, student id and class id. Otherwise the relationship table should consist of at least two fields, Class ID and Student ID, which combined form the unique key for each entry.

 

			   |ASSIGNEMENT||STUDENT|	  |-----------|	  |-------|	  |ASGN_ID	|	  |CLASS   ||ST_ID  |------|ST_ID	  |	  |--------|			   |CLASS_ID   |------|CLASS_ID|
Edited by eirikureiriksson (see edit history)

Share this post


Link to post
Share on other sites

the project is now complete, thanks for the advice.However, my supervisor said sometimes we may not use this kind of relation (many to many). He said we must break down the relation so that there will be no more many to many relation. Does this third table acceptable to make the whole relation to one to many?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.