Вопрос

Diagram

I created the following diagram:

Diagram

Considerations

So I will create two tables, one called Match and the other one called Teams. In Match there will be data about two teams, Away and Home.

Let us take into account that each team can have take part in many matches, and a match can have exactly two teams.

Questions

  • Is this considered a many-to-many (M:N) relationship?
  • Is there anything I can do to change it?
Это было полезно?

Решение

What i want to know is if this is considered a many to many relationship.

No, it is not a Many-To-Many. Match has two separate relationships with Team - Home Team and Away Team. These relationships are One-To-Many - One Team can have many Matches as Home Team but one Match has only one Home Team. This repeats for Away Team but they are not the same relationship.

And if there is anything is can do to change it?

To what, and why?

Yes, you could make these relationships Many-To-Many, so a Match can have many Home Teams and many Away Teams, but that data model doesn't fit the use case in this scenario - it has been modelled correctly already.

You could also make these relationships One-To-One, meaning a Team can only have one Home Match and one Away Match total, but again this data model would not fit the use case.

Другие советы

Is this your full design or just a trivial example?

Suppose you want to store information about a team in a match

  • who was captain of the team during the match
  • any kind of stats of the team during the match
  • and so ..

If this would be the case, I would opt for a many-to-many design.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с dba.stackexchange
scroll top