Oracle
 sql >> Datenbank >  >> RDS >> Oracle

SQL. Wie verweise ich auf einen zusammengesetzten Primärschlüssel Oracle?

 CONSTRAINT fk_column
 FOREIGN KEY (column1, column2, ... column_n)
 REFERENCES parent_table (column1, column2, ... column_n)

in Ihrem Fall

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)
);