1. Insert into table 1
  2. get the last_insert_id
  3. insert into table 2

On Wed, Jan 19, 2011 at 1:57 PM, James Nzomo <kazikubwa@gmail.com> wrote:

Hello folks Checkout this scenario

Table 1 columns -> | table_1_id (pkey) | some_column | comments |

Table 2 columns -> | table_2_id (pkey) | some_other_column | table_1_id (fkey) | comments |

All primary keys are of type serial or auto number. The 3rd column on Table 2 is an fk that references Table 1's primary key.

I would like to insert rows into both programmaticaly (from a c++ app)

Do i have to insert to table one then SELECT-query the entry's primary key then insert the Table 2 row with the pkey result?

Is there a more efficient way of handling this? Say using almost 2 queries?

PS. A postgresql specific solution would also work


_______________________________________________
Skunkworks mailing list
Skunkworks@lists.my.co.ke
http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks
------------
Skunkworks Rules
http://my.co.ke/phpbb/viewtopic.php?f=24&t=94
------------
Other services @ http://my.co.ke