Request two different servers

I need to request two different servers from a dynamically built request.

It basically receives data from one server, processes it, and inserts it onto another server.

The only problem is I must be sure that it works for both situations: If the source and target databases are on the same server, and if they are not.

I understand the concept of using Linked Servers in SQL Server, but I can’t think of a way to consider both alternatives, the same server, and different servers.

Help a little?

+4
source share
2 answers

Two linked servers are not needed ... only one server. Example

PhysicalServerA SQLServerA DatabaseA DatabaseB LinkedSQLServerB // A linked server to SQL Server B PhysicalServerB SQLServerB DatabaseC DatabaseD LinkedSQLServerA // A linked Server to SQL Server A 

Server A can now have queries for itself like:

 SELECT * FROM SQLServerA.DatabaseA.dbo.TableName 

And queries to LinkedSQLServerB like

 SELECT * FROM SQLServerB.DatabaseC.dbo.TableName 

Server B can now have queries such as:

 SELECT * FROM SQLServerB.DatabaseC.dbo.TableName 

And queries to LinkedSQLServerA, for example

 SELECT * FROM SQLServerA.DatabaseA.dbo.TableName 
+4
source

Use the full table name for both tables (local and remote)

SELECT * FROM SERVER.DATABASE.SCHEMA.TABLE

+1
source

Source: https://habr.com/ru/post/1310174/


All Articles