• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 177
  • Last Modified:

Got error creating a FK

Hi, I'm using sql 2005, sp3.  Please see the attached file for the error screen.  How to fix this?  thanks.
FkError.jpg
0
lapucca
Asked:
lapucca
  • 4
  • 2
1 Solution
 
jimyXCommented:
Are there any missing values in the Primary Key table?
0
 
lapuccaAuthor Commented:
What do you mean by missing values?  what am I looking for that's missing?  thank you.
0
 
lapuccaAuthor Commented:
If I remove "Check existing data upon creation" then the FL relationship is saved just fine.  I still like to correct this problem.  What should I check and correct ?  Thanks.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
lcohanDatabase AnalystCommented:
You should check all values and make sure no duplicates exists then you should be able to add it with check. Check related tables by that column as well for FKeys perspective.
0
 
lapuccaAuthor Commented:
Do you mean no duplicate rows?  I mean, it's 1 to many so personID is repeated in the history table.  
Can you elaborate on this "Check related tables by that column as well for FKeys perspective." ?  Thanks.
0
 
lcohanDatabase AnalystCommented:
Yeah my bad for that...that would be for the PK not FK as you can't add a PK on a table with duplicates..
And of course in a one to many relation you should check following for orphans:
You cant add a 1-many relation if the parent is missing so I would run smthing like:

select id from child_table
except
select id from parent_table

thias will give you the list of all children without parents and you need to
a: delete if possible as orphans
b: find the parent and restore the entry in parent_table.

hope this helps...
0
 
lapuccaAuthor Commented:
Great, thanks.  Orphan records is the culprit here.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now