Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cross-server SQL

I want to port data from one server's database to another server's database. The databases are both on a different mssql 2005 server. Replication is probably not an option since the destination database is generated from scratch on a [time interval] basis.

Preferebly I would do something like

insert * from db1/table1 into db2/table2 where rule1 = true 

It's obvious that connection credentials would go in somehwere in this script.

like image 559
Boris Callens Avatar asked Sep 16 '08 08:09

Boris Callens


People also ask

Can SQL join across servers?

There are 2 steps to join tables from different servers. The first step is to link the SQL Servers. The next and the last step is to join the tables using the select query having the server name as prefix for the table name.

Is SQL Server cross platform?

It's not just the cross-platform expansion which is new in 2017. New features have also been added to the platform. It should be noted that Microsoft has continued its cloud-first approach. Many of the new features in SQL Server 2017 have been available in Azure SQL.

What is cross-database query in SQL Server?

Example. This example illustrates a method to transfer data from one database into a memory-optimized table in a different database. Create Test Objects. Execute the following Transact-SQL in SQL Server Management Studio.


2 Answers

I think what you want to do is create a linked server as per this msdn article. You would then select using a 4 part object name eg:

Select * From ServerName.DbName.SchemaName.TableName 
like image 56
Matthew Pelser Avatar answered Sep 21 '22 22:09

Matthew Pelser


You can use Open Data Source Like this :

EXEC sp_configure 'show advanced options', 1 GO RECONFIGURE GO  EXEC sp_configure 'Ad Hoc Distributed Queries', 1 GO RECONFIGURE GO   SELECT  * FROM    OPENDATASOURCE('SQLOLEDB',                    'Data Source=<Ip Of Your Server>;                     User ID=<SQL User Name>;Password=<SQL password>').<DataBase name>.<SchemaName>.<Table Or View Name>  Go 
like image 27
Ardalan Shahgholi Avatar answered Sep 21 '22 22:09

Ardalan Shahgholi