How to have a foreign key pointing to two primary keys?

后端 未结 3 653
萌比男神i
萌比男神i 2020-12-18 09:35

I\'m trying to simplify a database structure, and I have two tables matches and team_statistics:

Here in the team_statistics

3条回答
  •  余生分开走
    2020-12-18 09:52

    I think you need to track teams to groups somewhere. Something like:

    CREATE TABLE team_groups (
        team_id int,
        group_id int,
        primary key (team_id, group_id)
    );
    

    then you need the matches table to have two foreign keys against this. Then your statistics table should reference that as well.

    You could aso create multiple foreign keys from team_statistics to matches but if you do this, you will run into an inability to grab statistics until a team is both on one side and the other side of a match.

提交回复
热议问题