我一直在网上搜索,erno 150似乎是一个常见的问题,但我正在努力解决这个代码,有什么帮助吗?
create table players
(
email varchar(30) not null,
playerpassword varchar(30),
screenName varchar (8),
primary key (email)
);
create table scores
(
screenName varchar(8),
gameword varchar(30),
score long,
foreign key (screenName) references players(screenName)
);
答案 0 :(得分:2)
screenName
需要是要在另一个表中用作外键的player表上的键。您只需将key (screenName)
添加到players
的表定义中即可。也许你甚至希望它是unique key
。
答案 1 :(得分:1)
您应该引用主键,而不是任意列。但是,我建议您使用自动递增的主键。像这样:
create table players (
playerId int not null auto_increment primary key,
email varchar(30) not null,
playerpassword varchar(30),
screenName varchar(8),
unique (email)
);
create table scores (
scoreId int not null auto_increment primary key
playerId int not null,
gameword varchar(30),
score long,
foreign key (playerId) references players(playerId)
);