Results 1 to 3 of 3

Thread: INSERT into one db SELECT results from another db

  1. #1
    Join Date
    May 2004
    Posts
    2

    INSERT into one db SELECT results from another db

    Is there a way to INSERT the data from the resultSet of a SELECT statement from one Database to another?

    I have two databases (currently on the same server, but will be on separate servers in production) that I want to be able to query one for data to be inserted into tables on the other. At the moment the only way I see to do it is to loop through the resultSet from the SELECT query and build a new INSERT statement to put the data in the second database. I was hoping some of you have done this more efficiently.

    I am using mysql for my database servers.

    thanks,
    Last edited by LonAllen; 05-28-2004 at 09:04 AM.

  2. #2
    Join Date
    May 2004
    Posts
    12
    i HAVE TWO EXAMPLES FOR THIS.. TRY



    INSERT INTO TABLE1
    SELECT * FROM TABLE2
    WHERE SOME CONDITION HERE


    SELECT COLUMN1
    INTO
    dbo.TABLE1
    FROM
    TABLE A,TABLE T
    WHERE T.Time_ID = A.Time_ID
    ORDER BY
    A.Unit DESC

  3. #3
    Join Date
    Nov 2002
    Location
    New Jersey, USA
    Posts
    3,932
    You can refer to another database using

    databasename.objectowner.tablename syntax.

    If the database is in a separate server, then you have to create a linked server to the other server and use four part naming convetion to refer to the table as

    linkedservername.databasename.objectowner.tablenam e

Posting Permissions

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