朋友我创建了一个包含三列复合主键的表,然后我创建了一个只引用两列的子表。这会产生错误..请帮助我仅从基表中引用两列。
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)
);
答案 0 :(得分:1)
答案 1 :(得分:1)
bookno从名为card_f的列中获取其值似乎很奇怪。
这种不正确的引用有几种不同的方法
, FOREIGN KEY (BOOKNO)
REFERENCES 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最适合您的情况。
答案 2 :(得分:0)
选项:
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 table