Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7605845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:16:09+00:00 2026-05-31T00:16:09+00:00

I am trying to create a composite foreign key relationship/constraint. All tables are empty.

  • 0

I am trying to create a composite foreign key relationship/constraint. All tables are empty. I have this table:

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]

and this table:

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]

and I want to link them like this:

alter table [ChemSampleValueEventLinkTest] add 
    constraint FK_ChemSampleValueEvent_ChemSampleValue_test
    foreign key ([SampleNumber], [ResultGroupID], [ParameterID]) 
    references ChemSampleValueTest ([SampleNumber], [ResultGroupID], [ParameterID])

As far as I can tell all column types are the same, but it keeps on saying

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’.

Where am I going wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T00:16:10+00:00Added an answer on May 31, 2026 at 12:16 am

    It looks like you need to have your FK/references list in the same order they appear in the PK definition.

    This should work:

    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]
    
    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]
    
    alter table [ChemSampleValueEventLinkTest] add 
        constraint FK_ChemSampleValueEvent_ChemSampleValue_test
        foreign key ([SampleNumber], [ParameterID], [ResultGroupID]) 
        references ChemSampleValueTest ([SampleNumber], [ParameterID], [ResultGroupID])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a composite key that mimicks the set of PrimaryKeys
I am trying to create a composite DataContext for a UserControl. Basically I have
I'm trying to create a table in SQL Server 2000, that has a composite
I'm trying to create a composite component for use in my Seam application, and
I'm trying to realise this table structure: http://www.img-teufel.de/uploads/Unbenannt1d4f8a349jpg.jpg (not embedded due to size) It
I'm trying to add a composite primary key to a class and having a
Pretty new to sqlite (and sql). Trying to modify one table using another. create
I'm trying to create a composite ASP.NET control that let's you build an editable
I have been trying to teach myself MEF, starting with this tutorial: http://blogs.msdn.com/b/brada/archive/2008/09/29/simple-introduction-to-composite-applications-with-the-managed-extensions-framework.aspx There
I am trying to create a relation/table in Oracle that is between two many

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.