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 4051396
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:11:22+00:00 2026-05-20T14:11:22+00:00

I am trying to add a foreign key to a table, and it give

  • 0

I am trying to add a foreign key to a table, and it give me the following error:

There are no primary or candidate keys in the referenced table ‘tbl_Person’ that match the referencing column list in the foreign key ‘P_ID’.

I have a tbl_Person, which is defined as:

P_ID INT (Primary Key)
f_Name,
l_Name

the other table is a comments table which is defined as:

C_ID INT,
Comments,
P_ID (should be the foreign key)

Trying to make a one to many relationship table, so when the user add a comment, it is referenced back to him, also, he can add onto the comments without initializing a new comment. Hopefully that makes a little sense.

Ex: Randy Bing enter “I love SQL”, his ID is 1, f_Name is Randy, l_Name is Bing, his comments are “I love Sql”. His comments should store a unique ID, as well as import his P_ID.

Later on when Randy wants to add onto the comment with the same C_ID where P_ID matches him without creating a new C_ID.

Here is the Code:

ALTER TABLE tbl_Comments 
ADD CONSTRAINT P_ID
FOREIGN KEY (P_ID) 
REFERENCES tbl_Person(P_ID)

Am I close to being on the right track?

  • 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-20T14:11:23+00:00Added an answer on May 20, 2026 at 2:11 pm

    This error usually means the datatypes are different between “Comments” and “Person”, assuming this is the actual message

    The SQL should be this

    ALTER TABLE tbl_Comments WITH CHECK ADD
     CONSTRAINT FK_Comments_Person FOREIGN KEY (P_ID) REFERENCES tbl_Person (P_ID)
    

    This matches what you added. So:

    • check datatypes are both int
    • ensure P_ID is primary key on tbl_Person
    • (Edit, Dec 2011) collation and length must be the same for varchar columns too
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to add a foreign key to an existing table, and was having
I'm trying to add a Foreign Key to a table, but database, Sql Server
I'm getting this error when trying to add a foreign key contraint: #1005 -
I am trying to add a foreign key constraint to a table in my
I'm trying to use LinqToEntities and just noticed that there are no foreign key
I'm trying to create a table in Navicat and immediately add a foreign key
I'm trying to create a foreign key on a table in MySQL and I'm
I am trying to bind a ComboxBox to a foreign key table. I know
I'm trying add a tab to my web page that looks like this: Using
trying to add an ExpiresDefault ExpiresByType to content on my website so that way

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.