Click here to Skip to main content
15,893,161 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I created primary key in a table and i created a foreign key in another table by refence primary key table. I have us identity column in primary key and foriegn key both . When i am inserting values in foriegn key table... I got this error. Plzz Give me Correct solution. ASAP
Posted
Comments
Raul Iloc 26-Mar-14 5:23am    
So what is the status with your problem? Did you try my solution?

You cannot insert a new value in the foreign key table when that value does not exist in the primary key table first, that is one of the rules of referential integrity enforced by the relational database management system (RDBMS). Read more what-is-referential-integrity[^]
 
Share this answer
 
This error signals that you are trying to insert data in your 2nd table for a Foreign Key (FK) that does not exit yet in the first table as Primary Key (PK), in other world there not exists a record in first table with PK equal with the FK that you want to add.

So first you should insert into your first table for that PK and then to insert in your 2nd table all rows that refer that PK as FK.
 
Share this answer
 
This error occurs when P_Id is not there and in referenced table you are trying to insert example

TABLE A: Student Table

S_Id(autogen Id) S_Name

1 leela
2 Sam
3 Mike

TABLE B: Student Record Table


S_RID(autogen Id) S_Id(FK) Subject

1 1 Maths
2 3 Science
4 4 GK -- this column we can't able to insert because S_Id 4 is not there in Parent Table

Hope its clear
 
Share this answer
 

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