ORA-02256:引用外键

时间:2014-11-16 03:43:53

标签: oracle sqlplus

我是一名SQL新手,在引用外键时遇到了一些麻烦

我的活动表:

create table Event
(
Bookid  number(5),
edate date,
FacID int,
GuestID int,
CONSTRAINT pk1edate PRIMARY KEY (edate,Bookid),
CONSTRAINT fk1Bookid FOREIGN KEY (Bookid) references BOOK (Bookid),
CONSTRAINT fk2FacID FOREIGN KEY (FacID) references CUSTOMER (SponsorID),
CONSTRAINT fk3GuestID FOREIGN KEY (GuestID) references CUSTOMER (SponsorID)
);   

和我的event_register表

create table EVENT_REGISTER
(
CID number(6),
Bookid  number(5),
edate date,
CONSTRAINT pk1Edate PRIMARY KEY (edate,Bookid),
CONSTRAINT fk2Bookid FOREIGN KEY (Bookid) references BOOK,
CONSTRAINT fk3edate FOREIGN KEY (edate) references Event (edate,Bookid)
);

当我尝试运行Event_Register时出现此错误:

ERROR at line 9:
ORA-02256: number of referencing columns must match referenced columns

1 个答案:

答案 0 :(得分:0)

您需要在引用时指定父表和子表中的所有列。

create table EVENT_REGISTER
(
CID number(6),
Bookid  number(5),
edate date,
CONSTRAINT pk1Edate PRIMARY KEY (edate,Bookid),
CONSTRAINT fk2Bookid FOREIGN KEY (Bookid) references BOOK(Bookid),
CONSTRAINT fk3edate FOREIGN KEY (edate,Bookid) references Event (edate,Bookid)
);