How can I select data in the same query from two different databases that are on two different servers in SQL Server?
相关问题
- SQL join to get the cartesian product of 2 columns
- sql execution latency when assign to a variable
- Difference between Types.INTEGER and Types.NULL in
- What is the best way to cache a table from a (SQL)
- php PDO::FETCH_ASSOC doesnt detect select after ba
I know this is an old question but I use synonyms. Supposedly the query is executed within database server A, and looks for a table in a database server B that does not exist on server A. Add then a synonym on A database that calls your table from server B. Your query doesn't have to include any schemas, or different database names, just call the table name per usual and it will work.
There's no need to link servers as synonyms per say are sort of linking.
As @Super9 told about OPENDATASOURCE using SQL Server Authentication with data provider SQLOLEDB . I am just posting here a code snippet for one table is in the current sever database where the code is running and another in other server '192.166.41.123'
Simplified solution for adding linked servers
First server
Second Login
Execute queries from linked to local db
Querying across 2 different databases is a distributed query. Here is a list of some techniques plus the pros and cons:
Server 2008:
When in SSMS connected to server1.DB1 and try:
as others noted, if it doesn't work it's because the server isn't linked.
I get the error:
To add the server:
reference: To add server using sp_addlinkedserver Link: [1]: To add server using sp_addlinkedserver
To see what is in your sys.servers just query it: