SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru
    Join Date
    Sep 2008
    Posts
    977
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Insert two two tables in one query??

    Hi,

    I wonder is it possible to do an insert to >1 table where each table is in a separate database?

    Code MySQL:
    insert into db1.table AND db2.table
        VALUES( ?, ?, ?, ? )
        WHERE 1

    I am trying to plan how to make a test db and a live db each have the same values so that I can test my scripts in a dummy environment and so, not break my live db.

    If not possible then I suppose I need to look into some method of database syncronisation or something.

    bazz

  2. #2
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,095
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    As can be seen in the manual, you can only insert values into one table at the time.

    You might want to look into transactions.

  3. #3
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,322
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by IBazz View Post
    If not possible ...
    it isn't

    Quote Originally Posted by IBazz View Post
    ... then I suppose I need to look into some method of database syncronisation or something.
    dump the database, open the sql file in a competent text editor, leave the CREATE TABLE statements as is, remove excess INSERT statements (the test database should normally not need to be as big as the live database), and then run the sql file to create your test database

    lather, rinse, repeat

    vwalah, eh

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  4. #4
    SitePoint Guru
    Join Date
    Sep 2008
    Posts
    977
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you both.

    Rudy, you make it all sound so simple. I'll give it a go in a couple of days and see how I get on.

    bazz


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
  •