Reputation: 13
Here is my option_table
:
OptionID QuestionID optionName OptionStatus count Questioncount percentage
30 33 a 1 4 8 50
31 33 b 1 4 8 50 <-----
71 48 k 1 3 7 42
72 48 p 1 4 7 58 <-----
Here i am trying to insert somevalues in to voting_table
.
fine its inserting
insert into Voting_Table (QuestionID,OptionID)values('33','31')
(1 row(s) affected)
trying to insert another one same as above
insert into Voting_Table (QuestionID,OptionID)values('48','72')
but its showing error
Msg 547, Level 16, State 0, Line 1 The INSERT statement conflicted with the FOREIGN KEY constraint "FK__Voting_ta_Optio_67B44C51". The conflict occurred in database "webdhabaordering_10-10-12", table "sqldbarv2008.Options_table", column 'OptionID'. The statement has been terminated.
How can I get rid this problem? Your valuable comments would be much appreciated.
Upvotes: 0
Views: 63
Reputation: 436
Isn't it says OptionID in sqldbarv2008.Options_table conflict means not existing in other words. may be you haven't committed your last row to options table yet? if that occurs it is visible in the view but underlying database table hasn't got the value until you commit it.
Upvotes: 1
Reputation: 3854
It seems you had some option table named as Options_table that does not have Primary Key may be named as "Option ID" value of 72.
This is why there is a error.
Study about Primary and Foreign Key more.
http://www.w3schools.com/sql/sql_foreignkey.asp
Upvotes: 1