Please help me understand further the many to many
relationship. Suppose I have Teacher and Students Table and in my understanding it is one-to- many
.
Teacher
TeacherId Primary Key
TeacherName
Student
StudentId Primary Key
TeacherId Foreign Key
StudentName
TeacherId
can appear several times in the Student Table.
I'm confused because Student can have many teacher.
- When can I say something is
one-to-many
and when is itmany to many
?
I can say One Student can have many teacher.
On the other hand, I can also say that One Teacher can have many student.
- If both of one teacher and one student can have many students(for teacher), many teacher(for students). How should I construct the table(s)?
- Is Student-Teacher relationship or vice versa can be considered
many-to-many
?
I understand that once I've properly identified the relationships, it would be easier for me to decide how many tables to create or whether or not there's a need to create a join table. From the tutorials and information I read online, it says that I should create a join-table
if the relationship is many-to-many
. So I thought it should look something like this.
Teacher
TeacherId Primary Key
TeacherName
Student
StudentId Primary Key
StudentName
Teacher_Student(join table)
Id Primary Key
TeacherId PRIMARY KEY
StudentId --took PKs of both Student and Teacher table.
Are there conditions to easily identify relationships, maybe if it's dependent on one table or not?
I'd appreciate any explanation. I just started learning this.
Thanks.