database - 如何为一个表设置两个外键,并且这些外键引用另一个表中的相同主键?
问题描述
下面给出了子表的创建......
create table match_detail (
match_id int primary key auto_increment,
team1_id int(5),
team2_id int(5),
foreign key (team1_id) references team(team_id),
foreign key(team2_id) references team(team_id)
);
父表数据如下......
create table team(
team_id int(5) primary key,
team_name varchar(20)
);
我想在子表(team1_id,team2_id)中创建两个外键,这两个字段引用另一个表(team_id,即团队表)中的相同主键列...
你能帮我解决这个问题吗?
解决方案
您的 SQL 不正确。
create table match_detail (match_id int primary key auto_increment,
team1_id int(5),
team2_id int(5),
foreign key (team1_id) references team(team_id),
foreign key (team2_id) references team(team_id))
推荐阅读
- python - 如何在 Flask 中线程化外部挂起 API 调用?
- c# - C# 中 ListView 的问题
- android - 我想在特定日期安排通知,我应该使用 workmanager 吗?
- c++ - 您如何更新priority_queue中的值,或者是否有另一种方法可以在c ++中更新堆中的键
- android - Android 媒体播放器不通过 HTTP 播放声音文件
- html - SASS 进口行为不端
- excel - 从 Outlook 保存 msg 附件并根据 msg 中的信息修改文件名
- ios - iOS - 选择模型类
- java - 生成后返回位串数组,而不仅仅是打印
- netlogo - NetLogo 实验设置