title: How to reference a composite primary key in SQL
body: <p>I have created the following 3 tables using the following code.</p>
  
  <pre><code>CREATE TABLE BUILDING(
  BUILDINGNO CHAR(2),
  BUILDINGWING VARCHAR2(15),
  BUILDINGLANE VARCHAR2(15),
  CONSTRAINT BUILDING_PK PRIMARY KEY(BUILDINGNO));
  
  CREATE TABLE ROOM(
  BUILDINGNO CHAR(2),
  ROOMNO CHAR(2),
  ROOMCAPACITY NUMBER(3),
  CONSTRAINT ROOM_PK PRIMARY KEY(BUILDINGNO,ROOMNO),
  CONSTRAINT ROOM_FK1 FOREIGN KEY(BUILDINGNO) REFERENCES BUILDING(BUILDINGNO));
  
  CREATE TABLE SPEAKER(
  SPEAKERID CHAR(2),
  SPEAKERNAME VARCHAR2(20),
  SPEAKERADDRESS VARCHAR2(50),
  SPEAKERPHONE CHAR(12),
  CONSTRAINT SPEAKER_PK PRIMARY KEY(SPEAKERID));
  </code></pre>
  
  <p>The 4th table i need to create is something like this.</p>
  
  <pre><code>CREATE TABLE CONFERENCESESSION(
  SESSIONID CHAR(4),
  BUILDINGNO CHAR(2),
  ROOMNO CHAR(2),
  SPEAKERID CHAR(2),
  SESSIONDATE DATE,
  SESSIONPRICE NUMBER(4,2),
  CONSTRAINT SESSION_PK PRIMARY KEY(SESSIONID),
  CONSTRAINT SESSION_FK1 FOREIGN KEY(BUILDINGNO) REFERENCES BUILDING(BUILDINGNO),
  CONSTRAINT SESSION_FK2 FOREIGN KEY(ROOMNO) REFERENCES ROOM(ROOMNO),
  CONSTRAINT SESSION_FK3 FOREIGN KEY(SPEAKERID) REFERENCES SPEAKER(SPEAKERID));
  </code></pre>
  
  <p>However I know that the constraint for the FK2 ROOMNO (2nd last line) is incorrect as the PK in the ROOM table is BUILDINGNO,ROOMNO.
  What would be the correct code to use for this line?</p>