SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    Jul 2008
    Posts
    220
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Red face insert into many tables with single query??

    let's go straight, say i have many diff tables and want to insert datas to all:--

    Code MySQL:
    INSERT INTO table_one VALUES('val_1', 'val_2', 'val_3')
    INSERT INTO table_two VALUES('val_5', 'val_6', 'val_7', 'val_8')
    INSERT INTO table_three VALUES('val_9', 'val_10')
    INSERT INTO table_four VALUES('val_11', 'val_12', 'val_13', 'val_14', 'val_15')
    .
    .
    .
    .

    this is too many round trip to DB server.

    can i do it with just one query?

    of course, if only one same table i can make one query like below:--

    Code MySQL:
    INSERT INTO table_one VALUES('val_1', 'val_2', 'val_3'), ('val_5', 'val_6', 'val_7', 'val_8'), ('val_9', 'val_10'), ('val_11', 'val_12', 'val_13', 'val_14', 'val_15')

    thank you very much!

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,215
    Mentioned
    58 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by leelong View Post
    can i do it with just one query?
    no
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •