有人可以帮帮我吗? 我正在尝试将这个表格用于某些课程,但我总是遇到外键问题,我不知道为什么......
当我尝试创建表时出现此错误:“缺少左括号”
CREATE TABLE Avatar
(
Avatar_ID NUMBER(3) CONSTRAINT pk_Avatar PRIMARY KEY,
AvatarName VARCHAR(255),
DOB NUMBER(12),
Gender VARCHAR(1),
Strength NUMBER(12),
Weapon VARCHAR(255),
Species VARCHAR(255),
Cost NUMBR(20),
Player_ID NUMBER(3), FOREIGN KEY REFERENCES Player(Player_ID),
MotherAvatar_ID NUMBER(3), FOREIGN KEY REFERENCES MotherAvatar(MotherAvatar_ID),
FatherAvatar_ID NUMBER(3), FOREIGN KEY REFERENCES FatherAvatar(FatherAvatar_ID)
);
答案 0 :(得分:0)
试试这个
CREATE TABLE Avatar
(
Avatar_ID NUMBER(3) CONSTRAINT pk_Avatar PRIMARY KEY,
AvatarName VARCHAR(255),
DOB NUMBER(12),
Gender VARCHAR(1),
Strength NUMBER(12),
Weapon VARCHAR(255),
Species VARCHAR(255),
Cost NUMBER(20),
Player_ID NUMBER(3), CONSTRAINT fk_playerid FOREIGN KEY (Player_ID) REFERENCES Player(Player_ID),
MotherAvatar_ID NUMBER(3), CONSTRAINT fk_MotherAvatar_ID FOREIGN KEY (MotherAvatar_ID) REFERENCES MotherAvatar(MotherAvatar_ID),
FatherAvatar_ID NUMBER(3),CONSTRAINT fk_FatherAvatar_ID FOREIGN KEY (FatherAvatar_ID) REFERENCES FatherAvatar(FatherAvatar_ID)
);
答案 1 :(得分:0)
在代码中添加了约束关键字
CREATE TABLE Avatar
(
Avatar_ID NUMBER(3) CONSTRAINT pk_Avatar PRIMARY KEY,
AvatarName VARCHAR(255),
DOB NUMBER(12),
Gender VARCHAR(1),
Strength NUMBER(12),
Weapon VARCHAR(255),
Species VARCHAR(255),
Cost NUMBR(20),
Player_ID NUMBER(3),
CONSTRAINT fk_player FOREIGN KEY (Player_ID ) REFERENCES Player(Player_ID) ,
MotherAvatar_ID NUMBER(3),
CONSTRAINT fk_ma FOREIGN KEY (MotherAvatar_ID) REFERENCES MotherAvatar(MotherAvatar_ID),
FatherAvatar_ID NUMBER(3),
CONSTRAINT fk_fa FOREIGN KEY (FatherAvatar_ID ) REFERENCES FatherAvatar(FatherAvatar_ID)
);