how to copy data from another sql server instance

  • Hi all,

    I need to import data from a table in one sql server instance to a table in another sql server instance.

    How to do it using transact-sql?

    Thank you.

    Betty

  • Create a linked server. Read BOL topic sp_addlinkedserver

    Once the link is created, T-SQL is as follows:

    INSERT INTO YourTable  (Column List)

    SELECT Column List

    FROM [LinkName].[DatabaseName].[DBOwner].[TableName]

     

  • The above command will only work if you have already created the table. After you link the server using sp_addlinkedserver or add the linked server in Enterprise Manager run this and it will create the table for you:

    SELECT * INTO newTable

    FROM [LinkedServer].[dbName].[Owner].[Table]

    This T-SQL will create the table for you based upon the columns and datatypes in the existing table.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply