Insert to Parent and Child Table SQL Statement (Full Version)

All Forums >> [Web Development] >> ASP and Database



Message


truwebs -> Insert to Parent and Child Table SQL Statement (4/12/2007 10:23:33)

Can somebody direct me on proper syntax of SQL statement to insert into one table that has child table in a relational database?

I can get the insert to work for the Parent, but a record also needs to be inserted into the Child. Below is an example of my tables. I get Table 1 to insert no problem. What I need is table 2 to populate based on the catID from table 1 which is primarty key and selected imgID from table 3. Thanks for your help.

EX.

Table 1
catID
imgID
venID


Table 2
catID
imgID


Table 3
imgID
imgName




Spooky -> RE: Insert to Parent and Child Table SQL Statement (4/13/2007 15:13:48)

Normally youll add them when the first record is inserted?
After an insert into table1, youll need to extract the ID of the new record and then perform an insert into table 2 using that new ID




truwebs -> RE: Insert to Parent and Child Table SQL Statement (4/13/2007 17:34:11)

I agree with you but, how do I do this?

All I have found is that I need to do a Select @@ Identity after the insert into table 1.

I am trying to do this with the .net framework using VB and an Access database.

Just don't know how to proceed with use of the Select@@Identity.

TRU




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.046875