如何为一个表设置两个外键,这些外键在另一个表中引用相同的主键?

时间:2018-05-21 09:46:13

标签: database relational-database

下面给出了子表创建.....

import socket
def sendSocketMessage(message):
    # Send a message to a socket
    try:
        client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        client.connect(('127.0.0.1', 8080)) 
        client.send(message)
        client.shutdown(socket.SHUT_RDWR)
        client.close()
    except Exception, msg:
        print msg

if __name__ == "__main__":
sendSocketMessage("message")

父表数据如下......

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)
);

我想在子表(team1_id,team2_id)中创建两个外键,其中这两个字段引用另一个表中的相同主键列(team_id,即team table)......

请你帮我解决这个问题?

1 个答案:

答案 0 :(得分:0)

您的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))
相关问题