View Single Post
Mentor
13Sep2008,04:58  
xpi0t0s's Avatar
If you store the return value from NEWID() somewhere, then you can insert into Table1 and Table2 from the same variable. Essentially just using a variable to replace your scratchpad.

If NEWID() is a database function and you performed INSERT INTO TABLE1 VALUES(NEWID(), 'name') then you'd replace this with something like SELECT NEWID() FROM DUAL into a host variable :V, then INSERT INTO TABLE1 VALUES(:V,'name) and INSERT INTO TABLE2 VALUES('book',:V).

Or you could combine the first two with something like INSERT INTO TABLE1 VALUES(NEWID(), 'name') RETURNING AUTHOR_ID INTO :V, if your database supports RETURNING.

Exact syntax will depend on what database you're using (specify author and complete version number if you want more detailed followup) and what language and API you're using to access the database.