title: SQL. How to reference a composite primary key Oracle?
body: <p>I have two parent tables: <code>Treatment</code> and <code>Visit</code>. </p>
  
  <p>Treatment table:</p>
  
  <pre><code> create table Treatment (
      TreatCode CHAR(6) constraint cTreatCodeNN not null,
      Name VARCHAR2(20),
      constraint cTreatCodePK primary key (TreatCode),
      );
  </code></pre>
  
  <p>Visit table:</p>
  
  <pre><code>create table Visit (
  SlotNum NUMBER(2),
  DateVisit DATE,
  ActualArrivalTime DATE,
  constraint cVisitSlotDatePK primary key (SlotNum, DateVisit)
  );
  </code></pre>
  
  <p>Now I try to create a child table:</p>
  
  <pre><code>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)
  );
  </code></pre>
  
  <p>Everything executes fine till the 3 line. Starting from the 3rd line, i.e. <code>SlotNum constraint ...</code> there is a message: <code>no matching unique or primary key</code>. There was already a <a href="https://stackoverflow.com/questions/6602099/oracle-composite-primary-key-foreign-key-question">similar question</a>, but i did not quite get the logic to apply in my case. I reference each column one by one, and it works for the <code>Treatment</code> table parent.  How should i correct reference <code>Visit</code> table parent?</p>