Re: SQL INSERT INTO multiple Tables- HELP!!!
Date: 1996/08/13
Message-ID: <4uq6uq$a2s_at_sousa.amt.tay1.dec.com>#1/1
In article <01bb874c$a8b94900$708264ce_at_raevaen.dimensional.com>, "SeanN" <raevaen_at_dimensional.com> writes...
>I need to do a nested parameter query and really need some help
>Table 1 has P_ID, a counter field. When I INSERT INTO Table 1, I also need
>to INSERT the P_ID (unknown until after the insert when it will be
>incremented) into Table 2. Alone with all this, some PARAMETERS need to go
>into Table 1 and Table 2.
>
>HELP!!!!
>
>It would be nice if something like:
>
>Parameters newName, newYear;
>INSERT INTO Table1 INNER JOIN Table2 ON Table1.P_ID=Table2.P_ID
>(Table1.Name, Table2.P_ID, Table2.Year)
>VALUES (newName, Table1.P_ID, newYear);
>
>could be done but this is totally incorrect. ACK! but it kinda shows what I
>need to do. HELP!!!
What database is this using ? The simplest is probably to break it down into two inserts:
INSERT INTO Table1 (Name, ....)
VALUES (newName, ....);
INSERT INTO Table2 (P_ID, Year, ...)
(select P_ID from Table1 where Name = newName), newYear, ...);
/albert
-- Albert Godfrind Oracle Rdb Engineering Oracle Corporation Email: agodfrin_at_fr.oracle.com DEC European Technical Center godfrind_at_heron.enet.dec.com 950 Route des Colles Phone: +33/92.95.51.63 06901 Sophia-Antipolis Mobile: +33/09.97.27.23 France FAX: +33/92.95.50.50 The statements and opinions expressed here are my own and do not necessarily represent those of Oracle Corporation.Received on Tue Aug 13 1996 - 00:00:00 CEST