2 个外键可以在一个 table 中引用另一个中的同一列吗?
Can 2 foreign keys be in one table referencing the same column in another?
2 个外键可以在一个 table 中引用关系模型中另一个中的同一列吗?
是的,在 match
table 中有两列引用 teams
table 是完全没问题的。这意味着:每场比赛涉及两支球队,并且这些球队中的每支球队都必须出现在 teams
table.
这是一些简化的 SQL 代码:
create table team (
team_id int primary key,
team_name varchar(50)
);
create table match (
match_id int primary_key,
home_team_id int references team(team_id),
away_team_id int references team(team_id),
date_of_match date
);
2 个外键可以在一个 table 中引用关系模型中另一个中的同一列吗?
是的,在 match
table 中有两列引用 teams
table 是完全没问题的。这意味着:每场比赛涉及两支球队,并且这些球队中的每支球队都必须出现在 teams
table.
这是一些简化的 SQL 代码:
create table team (
team_id int primary key,
team_name varchar(50)
);
create table match (
match_id int primary_key,
home_team_id int references team(team_id),
away_team_id int references team(team_id),
date_of_match date
);