Hello All,
I have 3 tables
solset with columns
solset_ID and Solset name
Solsubset
solsubset_id, subset name
subset_link
subset_link_id, solset_id(from solset), solsubset_id(solsubset)
I am trying to write an insert statement for the solsubset table and one for
subset_link. my insert for the solsubset table
INSERT INTO [dbo].[Solution_Subset] ([subset_Name]) VALUES (@subset_Name)
select solset_id from solution_sets where solset_id =@solset_Id
SET @Identity = SCOPE_IDENTITY()
INSERT INTO [dbo].[solset_subset_link] ([solset_id], [solsubset_id])
VALUES (@solset_id, @identity)
END
Error
Msg 547, Level 16, State 0, Procedure insertsubset, Line 18
The INSERT statement conflicted with the FOREIGN KEY constraint
"FK_solset_subset_link_Solution_Sets". The conflict occurred in database
"sosdb", table "dbo.Solution_Sets", column 'Solset_Id'.
How do I create my procedure, where I can insert into the solsubset table
and to the subset_link table
Here is the data, I am trying to have in the three tables
Solset table
Solset ID name
1 set1
2 set2
subsettable
subset_id name
1 subset1
2 subset2
3 subset3
subsetlink
subset_link_id solset_id subset_id
1 1 1
2 1 2
3 1 3
4 2 1
5 2 3
6 3 2
Thanks in Advance
Shri
with these statements, I get the error
Razvan Socol - 22 Jul 2008 20:01 GMT
The error message is saying that the @solset_id that you have specified
does not exist in the Solution_Sets table.
Make sure you are calling your procedure with the correct parameters.

Signature
Razvan Socol
SQL Server MVP