views:

70

answers:

3

I have project which contain 4 tables among these shedule table Session column i am not able to add vaue,,this table contain

three foriegn key from two tables(in which single table has two foreign keys here) i added values here..Any one has any idea about this..Actually my intention is to remove the error "the insert statement conflicted with the foreign key constraint sql server"

Table Shedule contains session number as primary key,,it is used as foreign key in Q&A table.Table Q&A contains Question num as primary key .Table Employee contain Employeeid as primary key which is used as foriegn key in Q&A table two times foriegn key as in Shedule table .Table Topic contain Topicid as primary key which is used forign key in Shedule table ans Q&A table Here my problem is i cant add values for session column in Shedule table(which is a primary key) second is whenever i insert values in Q&A table i am getting error like this Error Message: The INSERT statement conflicted with the FOREIGN KEY constraint "FK_QandA_Schedule". The conflict occurred in database "secon", table "dbo.Schedule", column 'Session_No'. The statement has been terminated.

+1  A: 

the insert statement conflicted with the foreign key constraint sql server

Obviously, you're trying to insert some value into one of the foreign-key fields that isn't a valid value in the referenced table.

You say you have three columns - check each of those against the tables they reference - shouldn't be too hard to figure out which one is not valid - and then use a valid value instead. That's the whole point of referential integrity - make sure you don't insert invalid data into your tables!

marc_s
But before that i am not able to add a single value in column Session in shedule table which is a primary key ,,is there anysettings i do here
peter
@Peter: Can you show us the four tables involved, and how they're set up, and what exactly you're trying to do??
marc_s
+1  A: 

The Error means what it says. That is, it doesn't have a column according to that id in a parent table.

To be more specific, please show us tables and INSERT statement.

UPDATE: If I got you right:

1) You try to INSERT a row into table Shedule, right?

If so, you need to have the Employeeid in table Employee and a Topicid in table Topic, that you're trying to INSERT. I suppose, you don't have a valid Q&A foreign key value, according to error message. That means, the Q&A foreign key value you're trying to add in your INSERT statement must exist in Q&A Table.

2) You try to INSERT a row into table Q&A?

For this table you need to have valid Employeeid (2 of them?), Topicid and Session_number.

P.S. But I can't tell what's your problem if you don't show us INSERT statements.

hgulyan
But before that i am not able to add a single value in column Session in shedule table which is a primary key ,,is there anysettings i do here
peter
@peter, if you have a foreign keys in Shedule table, you need to have values that you try to insert in the parent tables, before you insert a row. Can you, please, add table structures and insert statement?
hgulyan
i edited my question
peter
@peter, check the update in my answer.
hgulyan
A: 

I used a Cascade rule. It's working temporarily, but I don't know the consequences.

peter