SQL错误:ORA-00904:标识符无效

时间:2014-04-19 22:15:55

标签: sql oracle

我在创建此表后尝试添加外键

Create table Member
(
memeberID int Not null Primary Key,
mebershipID int Not null,
group_id  int not NULL,
Dutycode int not null,
MemberRole varchar(255),
name varchar(255),
last_joined date,
DOB date,
address varchar(255),

CONSTRAINT fk_DutCodes FOREIGN KEY (Dutycode)
REFERENCES RaceManagementDuty(Dutycode),


CONSTRAINT fk_GrMemeberinMemeber FOREIGN KEY (group_id)
REFERENCES Group_member(group_id),

CONSTRAINT fk_Mebersids FOREIGN KEY (mebershipID)
REFERENCES Membership(mebershipID)
)

我想创建的外键是使用Alter表的Sailnumber:

ALTER TABLE会员 添加外键(帆船号码) 参考船(帆船)

帆船是桌船的主要钥匙,如下所示

Create table Boat
(
sailnumber  int not null Primary Key,
mebershipID  int not NULL,
group_id int not NULL,
sizeOfBoat decimal(5,2),
weight decimal(5,2),
sailarea integer,
numberOfCrew integer,
portsmouthNumber integer,

CONSTRAINT fk_MebersidsBoat FOREIGN KEY (mebershipID)
REFERENCES Membership(mebershipID),


CONSTRAINT fk_GrMemeberinMemebers FOREIGN KEY (group_id)
REFERENCES Group_member(group_id)
)

但是,我收到此错误SQL错误:ORA-00904:" SAILNUMBER":无效的标识符,我不知道为什么我能得到任何人都可以告诉我我在哪里#39;我错了?

1 个答案:

答案 0 :(得分:1)

您需要将Sailnumber列添加到Member表中(在执行add foreign key查询之前)

ALTER TABLE Member ADD sailnumber INT NOT NULL;
ALTER TABLE Member ADD FOREIGN KEY (sailnumber) REFERENCES Boat(sailnumber);

或在一个查询中:

ALTER TABLE member 
ADD sailnumber INT NOT NULL CONSTRAINT sailnumber REFERENCES boat(sailnumber);