1

I am using SQL Server 2012 and I need to write a T-SQL query (that I will use as a SQL job) to copy a table (say, T1) located in a database (say, db1) on a linked Server to another database (say, db2).

Table T1 does not currently exist in database db2.

Assuming the table schema of T1 on the linked server is [xxx.xx.x.xx].db2.dbo.T1, how do I write this T-SQL query?

user3115933
  • 4,303
  • 15
  • 54
  • 94
  • Please check [this](https://stackoverflow.com/questions/187770/copy-tables-from-one-database-to-another-in-sql-server) – Fmanin Jan 17 '18 at 07:39
  • 2
    Possible duplicate of [Copy tables from one database to another in SQL Server](https://stackoverflow.com/questions/187770/copy-tables-from-one-database-to-another-in-sql-server) – Richard Jan 17 '18 at 07:45

1 Answers1

1

You may use OPENDATASOURCE. In Your destination Server database, Just Run

SELECT 
    *
    INTO dbo.DestinationTable
    FROM 
       OPENDATASOURCE
       (
          'SQLOLEDB', 
          'Data Source=SourceServer;User ID=MyUser;Password=MyPass'
       ).SourceDatabase.dbo.SourceTable;
Jayasurya Satheesh
  • 7,826
  • 3
  • 22
  • 39