Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
DB Engine
SQL ServerMSDESQL Server CE
Services
Analysis (Data Mining)Analysis (OLAP)DTSIntegration ServicesNotification ServicesReporting Services
Programming
CLRConnectivitySQLXML
Other Technologies
ClusteringEnglish QueryFull-Text SearchReplicationService Broker
General
Data WarehousingPerformanceSecuritySetupSQL Server ToolsOther SQL Server Topics
DirectoryUser Groups
Related Topics
MS AccessOther DB ProductsMS Server Products.NET DevelopmentVB DevelopmentJava DevelopmentMore Topics ...

SQL Server Forum / Programming / SQL / July 2008

Tip: Looking for answers? Try searching our database.

Procedure to insert into multiple tables

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
formcreator - 22 Jul 2008 17:51 GMT
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

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.