Solved

Got error creating a FK

Posted on 2011-03-10
7
169 Views
Last Modified: 2012-05-11
Hi, I'm using sql 2005, sp3.  Please see the attached file for the error screen.  How to fix this?  thanks.
FkError.jpg
0
Comment
Question by:lapucca
  • 4
  • 2
7 Comments
 
LVL 24

Expert Comment

by:jimyX
ID: 35098762
Are there any missing values in the Primary Key table?
0
 

Author Comment

by:lapucca
ID: 35099902
What do you mean by missing values?  what am I looking for that's missing?  thank you.
0
 

Author Comment

by:lapucca
ID: 35099947
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 39

Expert Comment

by:lcohan
ID: 35099960
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
 

Author Comment

by:lapucca
ID: 35099985
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
 
LVL 39

Accepted Solution

by:
lcohan earned 500 total points
ID: 35100151
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
 

Author Closing Comment

by:lapucca
ID: 35100872
Great, thanks.  Orphan records is the culprit here.
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you having speed problem in loading SQL Server Management Studio, try to uncheck these options in your internet browser (IE -> Internet Options / Advanced / Security):    . Check for publisher's certificate revocation    . Check for server ce…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

838 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question