can any one please clarify my error?

Posted by Tejamanimala under ASP.NET on 5/13/2013 | Points: 10 | Views : 736 | Status : [Member] | Replies : 2
The INSERT statement conflicted with the FOREIGN KEY constraint "FK__StudentEx__UserI__5441852A". The conflict occurred in database "OnlineExam", table "dbo.Resultsforstudents", column 'UserID'.
The statement has been terminated.
am geting this error,acn you please clarify,wht should i getting this error?
i have two tables resultsforstudents(columns are UserID,UserName,domaiin,marks where userid is primerkey)
2)studentExamFullResult(columns areUserID,QuestionID,Question,SelectedOption,CorrectOption where UserID is a foreign key)and database name is onlineexam

manimala


Responses

Posted by: Kmandapalli on: 5/13/2013 [Member] Silver | Points: 25

Up
0
Down
Hi,

In your table dbo.Resultsforstudents, it has a foreign key reference to another table. The way a FK works is it cannot have a value in that column that is not also in the primary key column of the referenced table.

If you have SQL Server Management Studio, open it up and sp_help 'dbo.dbo.Resultsforstudents'. See which column that FK is on, and which column of which table it references. You're inserting some bad data.

Also, check whether the naming conventions are given correctly or not...

Let me know if you need anything explained better!

Mark as Answer if satisfied............

Regards,
Shree M.


Kavya Shree Mandapalli

Tejamanimala, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Kmandapalli on: 5/13/2013 [Member] Silver | Points: 25

Up
0
Down
Hi,

If you have constraint specified in the table, you should ensure that you are inserting the same id into first table that exists into the second table (constraint table - foreign key table) otherwise you will get error.

Looks like the data you are going to insert doesn't exist into the foreign key table.

Mark as Answer if satisfied....

Regards,
Shree M.

Kavya Shree Mandapalli

Tejamanimala, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response