我有两个父表:Treatment和Visit。
Treatment
Visit
处理表:
create table Treatment ( TreatCode CHAR(6) constraint cTreatCodeNN not null, Name VARCHAR2(20), constraint cTreatCodePK primary key (TreatCode), );
访问表:
create table Visit ( SlotNum NUMBER(2), DateVisit DATE, ActualArrivalTime DATE, constraint cVisitSlotDatePK primary key (SlotNum, DateVisit) );
现在,我尝试创建一个子表:
create table Visit_Treat ( TreatCode constraint cTreatCodeFK references Treatment(TreatCode), SlotNum constraint cSlotNumFK references Visit(SlotNum), DateVisit constraint cDateFK references Visit(DateVisit), constraint cVisitTreatPK primary key (SlotNum, TreatCode, DateVisit) );
一切正常,直到第3行。从第三行开始,即SlotNum constraint ...显示一条消息:no matching unique orprimary key。
SlotNum constraint ...
no matching unique orprimary key
CONSTRAINT fk_column FOREIGN KEY (column1, column2, … column_n) REFERENCES parent_table (column1, column2, … column_n)
在你的情况下
create table Visit_Treat ( TreatCode CHAR(6) constraint cTreatCodeFK references Treatment(TreatCode), SlotNum NUMBER(2), DateVisit DATE, constraint cVisitTreatPK primary key (SlotNum, TreatCode, DateVisit), constraint fk_slotnumDatevisit FOREIGN KEY(SlotNum,DateVisit) references Visit(SlotNum,DateVisit) );