Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Greetings ...

I have two Tables in SQL Server, EMP and IDs.
EMP has general information like name, gender, phone, address, ... .
and IDs has Numbers of Identification cards and other information about them.
I have made One to One relationship between primary keys of the two tables.

The IDs table allows Insert command, but The EMP table DOES NOT.
and shows this message
"Insert statement conflicts with FK constraint" and states the names of the relation and the foreign keys.

Why is that happened ?? Thank u all


P.S:
1- The Primary keys for the two tables are the same name "ID"
2- The Relationship with "no action" relational integrity.
3- The Primary keys for the both of the tables are int auto increment
4- the EMP table has other 1 to 1 and 1 to M relationships with other tables
Posted
Updated 5-Jan-15 3:00am
v2
Comments
ZurdoDev 5-Jan-15 9:00am    
The error means that you're trying to insert a value into the table that does not exist in the foreign table.
Ali Albasri 5-Jan-15 9:09am    
I added a record in that table but to no avail, note that the two tables are 1 to 1 related
ZurdoDev 5-Jan-15 9:13am    
I don't follow what you're saying.

However, the error is pretty clear.
Ali Albasri 5-Jan-15 9:12am    
even though, let`s say that if i want to leave IDs without add a record to, like make a record for the employee with no Identification docs at the moment.
Tomas Takac 5-Jan-15 9:19am    
Can you post the structure of the tables along with the FK? In form of a create script maybe?

Read this to understand the root cause:
1. FOREIGN KEY Constraints[^]
2. SQL FOREIGN KEY Constraint[^]
 
Share this answer
 
Comments
TheRealSteveJudge 5-Jan-15 10:27am    
5*
 
Share this answer
 
Comments
TheRealSteveJudge 5-Jan-15 10:27am    
5*
Pratik Bhuva 6-Jan-15 4:25am    
Thanks :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900