MySQL inserting into multiple tables linked records

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • monomaniac21

    MySQL inserting into multiple tables linked records

    Hi all

    Using MySQL can anyone tell me how to most efficiently insert a collumn
    in 'table1' retrieve the id from this record and insert mutliple
    records into 'table2' with a collumn for the id in 'table1' which links
    the two recordsets

  • Marcin Dobrucki

    #2
    Re: MySQL inserting into multiple tables linked records

    monomaniac21 wrote:[color=blue]
    > Hi all
    >
    > Using MySQL can anyone tell me how to most efficiently insert a collumn
    > in 'table1' retrieve the id from this record and insert mutliple
    > records into 'table2' with a collumn for the id in 'table1' which links
    > the two recordsets[/color]

    set auto_commit=0
    insert into foo values (...)
    select last_insert_id( )
    insert into bar values (....)
    set auto_commit=1

    Comment

    • monomaniac21

      #3
      Re: MySQL inserting into multiple tables linked records

      Thanks for the response Marcin but i still dont quite understand. could
      you be any more elaborate please. Sorry.

      Marcin Dobrucki wrote:[color=blue]
      > monomaniac21 wrote:[color=green]
      > > Hi all
      > >
      > > Using MySQL can anyone tell me how to most efficiently insert a collumn
      > > in 'table1' retrieve the id from this record and insert mutliple
      > > records into 'table2' with a collumn for the id in 'table1' which links
      > > the two recordsets[/color]
      >
      > set auto_commit=0
      > insert into foo values (...)
      > select last_insert_id( )
      > insert into bar values (....)
      > set auto_commit=1[/color]

      Comment

      Working...