Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2007

    Unanswered: Copy a table from one DB to another DB

    HI All,

    i have 2 databases x and y

    a table in x named as table1

    i am looking to copy 'table1' from database x to database y say named 'table2'

    Database y doesnt have a table1

    Version: SQL Server 2000

    How to do this on Query Analyzer and/or Enterprise Manager???


  2. #2
    Join Date
    Nov 2004
    on the wrong server
    Provided Answers: 6
    use this if table 2 does not exist in y.

    select column1,column2
    into y.dbo.table2
    from x.dbo.table1

    if table 2 does exist, use this...

    INSERT INTO y.dbo.table2(column1,column2)
    SELECT column1,column2
    FROM x.dbo.table1
    “If one brings so much courage to this world the world has to kill them or break them, so of course it kills them. The world breaks every one and afterward many are strong at the broken places. But those that will not break it kills. It kills the very good and the very gentle and the very brave impartially. If you are none of these you can be sure it will kill you too but there will be no special hurry.” Earnest Hemingway, A Farewell To Arms.

  3. #3
    Join Date
    May 2007
    Generate create table script and run it on y database then use import / export utility to transfer data.

    SQL queries posted by Thrasymachus will also create new table and transfer data but if you need table dependent objects like triggers, constraints or indexes on your second database also, this way is useless.
    Mihir Mehendale
    DB Team @ Clarion
    Clarion Technologies
    (SEI CMMI Level 3)
    Pune, India

  4. #4
    Join Date
    May 2004
    also, if you are copying millions of rows, better to use bcp with the -b flag.

    otherwise your tlog will bloat.

Posting Permissions

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