title: Creating composite foreign key constraint
body: <p>I am trying to create a composite foreign key relationship/constraint.  All tables are empty.  I have this table:</p>
  
  
  
  <pre class="lang-sql prettyprint-override"><code>CREATE TABLE [dbo].[ChemSampleValueTest](
      [SampleNumber] [int] NOT NULL,
      [ParameterID] [int] NOT NULL,
      [Value] [numeric](18, 6) NOT NULL,
      [Accuracy] [varchar](50) NULL,
      [ResultGroupID] [int] NOT NULL,
      [QAState] [nvarchar](32) NOT NULL,
       CONSTRAINT [PK_SampleValueTest] PRIMARY KEY CLUSTERED 
      (
          [SampleNumber] ASC,
          [ParameterID] ASC,
          [ResultGroupID] ASC
      )
  ) ON [PRIMARY]
  </code></pre>
  
  <p>and this table:</p>
  
  <pre class="lang-sql prettyprint-override"><code>CREATE TABLE [dbo].[ChemSampleValueEventLinkTest](
      [Event] [int] NOT NULL,
      [SampleNumber] [int] NOT NULL,
      [ResultGroupID] [int] NOT NULL,
      [ParameterID] [int] NOT NULL,
      [QAState] [nvarchar](32) NULL
  ) ON [PRIMARY]
  </code></pre>
  
  <p>and I want to link them like this:</p>
  
  <pre class="lang-sql prettyprint-override"><code>alter table [ChemSampleValueEventLinkTest] add 
      constraint FK_ChemSampleValueEvent_ChemSampleValue_test
      foreign key ([SampleNumber], [ResultGroupID], [ParameterID]) 
      references ChemSampleValueTest ([SampleNumber], [ResultGroupID], [ParameterID])
  </code></pre>
  
  <p>As far as I can tell all column types are the same, but it keeps on saying</p>
  
  <blockquote>
    <p>There are no primary or candidate keys in the referenced table 
    'ChemSampleValueTest' that match the referencing column list in the foreign key
    'FK_ChemSampleValueEvent_ChemSampleValue_test'.</p>
  </blockquote>
  
  <p>Where am I going wrong?</p>