title: SQL Server : creating a table with a multi-column foreign key
body: <p>I have to create a set of tables in SQL Server. </p>
  
  <p>Those are: </p>
  
  <ul>
  <li><code>chips</code>, for identifying a chip to be implanted to an animal</li>
  <li><code>signals</code>, because every chip generates a signal once every hour</li>
  <li><code>signal receivers</code>, stations which can receive a signal if a chip is in its radius</li>
  <li><code>signal receivings</code>, for signals that have been received by a receiver</li>
  </ul>
  
  <p>I have a problem in creating those tables. </p>
  
  <p>This is my code: </p>
  
  <pre><code>CREATE TABLE CHIPS (
      ID INT PRIMARY KEY,
      ...(not related attributes)...
      );
  
  CREATE TABLE RECEIVERS (
      ID_receiver INT PRIMARY KEY,
      ...(some other attributes, not related to the problem)...
      );
  
  CREATE TABLE SIGNALS (
      ID_chip INT FOREIGN KEY REFERENCES CHIPS, 
      Signal_no INT, 
      Date DATETIME, 
      PRIMARY KEY (ID_chip, Signal_no)
      );
  
  CREATE TABLE SIGNAL_RECEIVINGS (
      ID_receiver INT REFERENCES RECEIVERS ,
      Id_chip INT REFERENCES SIGNALS(ID_chip), 
      Signal_no INT REFERENCES SIGNALS(Signal_no), 
      PRIMARY KEY (Id_chip, Signal_no, ID_receiver ) 
      );
  </code></pre>
  
  <p>My problem is that I don't know how to make a proper key for the <code>SIGNAL_RECEIVERS</code>. I want it to be <code>(Id_chip, Signal_no, ID_receiver)</code> because only then it would be unique, but SQL prints out an error : </p>
  
  <blockquote>
    <p>The number of columns in the referencing column list for foreign key 'FK__SIGNAL_R__Si_no__5C187C73' does not match those of the primary key in the referenced table 'SIGNALS'.</p>
  </blockquote>
  
  <p>Could someone help me out on this one? </p>