朋友的:我创建了一个具有三列的复合主键的表,然后我创建了一个子表,这个子表只引用了两个columns.this,这将使error..please帮助我从基表中只引用两列。
CREATE TABLE STUDENT
( SID NUMBER
, NAME VARCHAR2(20)
, DEPT VARCHAR2(20)
, CARD_F NUMBER
, CARD_S NUMBER
, PRIMARY KEY (SID, CARD_F, CARD_S)
);
CREATE TABLE MASTER
( BOOKNO NUMBER
, CARD_S NUMBER
, FOREIGN KEY (BOOKNO)
REFERENCES STUDENT(CARD_F)
); 发布于 2012-08-30 16:56:17
外键是另一个表中的键。不能引用不是key的元组。
请参阅以下W3schools的外键页面:
一个表中的外键指向另一个表中的主键。
(link)
发布于 2012-08-30 17:34:45
bookno从一个名为card_f的列中获取它的值似乎很奇怪。
这种错误的引用有几种不同的方式
, FOREIGN KEY (BOOKNO)
REFERENCES STUDENT(CARD_F)是可以修复的。
在student.card_f.
foreign key (card_s, card_f) references student (card_s, card_f).
foreign key (sid, card_s, bookno) references student (sid, card_s, card_f).引用完整的键
其中,3、4和5最有可能适用于您的情况。
发布于 2012-08-30 17:40:08
选项:
1> Please check if you can create a unique Key on the two columns on the base table the you want to refer to.
2> a)If you cant create unique key then intoduce a 3rd table which would maintain
distinct combination of column values for columns, to be included in F.K.
through a trigger on base table.
b)Make columns in your child table refer(F.K) to this newly introduced tablehttps://stackoverflow.com/questions/12193206
复制相似问题