Configuring Linked Servers

A linked server configuration allows Microsoft® SQL Server™ to execute commands against OLE DB data sources on different servers. Linked servers offer these advantages:

Linked Server Components

A linked server definition specifies an OLE DB provider and an OLE DB data source.

An OLE DB provider is a dynamic-linked library (DLL) that manages and interacts with a specific data source. An OLE DB data source is any data file accessible through OLE DB. Although data sources queried through linked server definitions are usually databases, OLE DB providers exist for a wide variety of files and file formats, including text files, spreadsheet data, and the results of full-text content searches. The following table shows examples of the most common OLE DB providers and data sources for SQL Server.

OLE DB provider OLE DB data source
Microsoft OLE DB Provider for SQL Server SQL Server database, such as pubs or Northwind
Microsoft OLE DB Provider for Jet Pathname of .mdb database file
Microsoft OLE DB Provider for ODBC ODBC data source name (pointing to a particular database)
Microsoft OLE DB Provider for Oracle SQL*Net alias that points to an Oracle database
Microsoft OLE DB Provider for Indexing Service Content files on which property searches or full-text searches can be run


Note This release has been tested only against the Microsoft OLE DB Provider for SQL Server, Microsoft OLE DB Provider for Jet, Microsoft OLE DB Provider for Oracle, Microsoft OLE DB Provider for Indexing Service, and the Microsoft OLE DB Provider for ODBC. However, SQL Server distributed queries are designed to work with any OLE DB provider that implements the requisite OLE DB interfaces.


For a data source to return data through a linked server, the OLE DB provider (DLL) for that data source must be present on the same server as SQL Server.

Linked Server Details

This illustration shows the basics of how a linked server configuration functions.

Linked servers are typically used to handle distributed queries. When a client application executes a distributed query through a linked server, SQL Server breaks down the command and sends rowset requests to OLE DB. Rowsets are the central objects that enable all OLE DB data providers to expose data in tabular form. Conceptually, a rowset is a set of rows in which each row contains columns of data.

OLE DB then queries the provider for the rowset information. The provider, in turn, knows the specifics of calling the data source, opening the file, and returning the requested information. The rowset data is returned through the provider and OLE DB to SQL Server, where it is reconstructed and returned to the client application as a result set and set of output parameters (if applicable).

Managing a Linked Server Definition

When setting up a linked server, register the connection information and data source information with SQL Server. After registration is accomplished, that data source can always be referred to with a single logical name.

You can create or delete a linked server definition with stored procedures or through SQL Server Enterprise Manager.

Executing a Distributed Query

When executing a distributed query against a linked server, include a fully qualified, four-part table name for each data source to query. This four-part name should be in the form linked_server_name.catalog.schema.object_name. For example, to run a “SELECT * FROM employees” query against a SQL Server data file and an Oracle data file, the distributed query would look similar to the following:

SELECT emp.EmloyeeID, ord.OrderID, ord.Discount

FROM SQLServer1.Northwind.dbo.Employees AS emp,

     OracleSvr.Catalog1.SchemaX.Orders AS ord

WHERE ord.EmployeeID = emp.EmployeeID

      AND ord.Discount > 0

  

See Also
Distributed Queries Identifying a Data Source Using a Linked Server Name
OLE DB Providers Tested with SQL Server Using Transactions with Distributed Queries

  


(c) 1988-98 Microsoft Corporation. All Rights Reserved.