Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 MULTIPLE INSERT statement HELP please...

Author  Topic 

Sirrombor
Starting Member

12 Posts

Posted - 2002-07-01 : 15:25:42
I am still somewhat new to SQL so please be kind to me :)

I am using SQL SERVER 2000 and working with WebForms using C#...

I have 2 tables that I am working with...

TABLE_1
TABLE_1_ID = primary key Identity Auto Increment
STATUS = Some Insert Values

TABLE_2
TABLE_2_ID = primary key Identity Auto Increment
TABLE_1_ID - Foreign key from TABLE_1 TABLE_1_ID
Column1 = Some Insert Values
Column2 = Some Insert Values
Column3 = Some Insert Values


I have just realized that I have no clue on how to insert a value into TABLE_1 which generates a unique ID and at the same time insert into TABLE_2 Values while relating the Table 2 values to the Unique ID that was generated in Table_1_ID...

Any help will be greatly appreciated......


AjarnMark
SQL Slashing Gunting Master

3246 Posts

Posted - 2002-07-01 : 15:29:31
The inserts will have to be done as two separate commands. To maintain data integrity, you probably will want to explicitly declare a transaction. Do the INSERT to Table1 first, then retrieve the @@IDENTITY or SCOPE_IDENTITY into a variable and use that variable in the INSERT to table2.

You can save yourself some headaches of you'll put this whole bit of code into a stored procedure and call the sproc from your C# code rather than trying to have C# make multiple calls.

Go to Top of Page

Sirrombor
Starting Member

12 Posts

Posted - 2002-07-01 : 16:09:50
Its all clear now...

Thank you I know just what I need to do :)

Go to Top of Page
   

- Advertisement -