创建此表后,我试图添加外键

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成员添加外键(航行号)参考航行船(航行号)

sailnumber是桌船的主键,如下所示

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”:无效的标识符,我不确定为什么会得到这个错误。有人可以告诉我我要去哪里了吗?

===============>>#1 票数: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);

  ask by Sky translate from so

未解决问题?本站智能推荐:

关注微信公众号