Try to get some professional idea here about which choice is better when creating schema relationships
I roughly find an idea from this post but still try to get more thinkings.
A simple scenario could be like this:
class <--> Student <--> Teacher <--> class
(Assume a teacher can teach multiple classes)
it is a normal scenario with many-to-many relationship in a round. And query can start from any peer to any direction. So what could be a better design?
I know in one to one relationship a mapping table is definitely a waste, but is the mapping table solution ONLY good for many-to-many relationship, like that post mentioned? If we want to extend the many to many relationship with directions. If the relationship is one-direction instead of bidirectional, could the answer be different?
Thanks in advance.
Some simple rules:
For a one-to-one relationship, a foreign key can be held in either of the tables involved in the relationship, referencing the other table.
For a one-to-many relationship, the table on the many side of the relationship should hold the foreign key.
For a many-to-many relationship, you can create an association table (mapping table in your terms), which is a third table that holds foreign keys to both of the tables involved in the many-to-many relationship.
For example, assume we have the tables
STUDENT,CLASS, andTEACHER. Generally, there is a many-to-many relationship betweenSTUDENTandCLASS, and a one-to-many from TEACHER to CLASS (assuming a class only has one teacher). So, these tables might look like: