Introduction
An increasing number of applications require access to multiple databases located at different sites, perhaps widely separated geographically.
A common business scenario is a retailer with a network of warehouses spread across the country in order to speed delivery of its products. A distributed database system allows applications to access database local and remote transparently.
When data might be distributed? Why not gather all data of the enterprise in one central site? There are answers to these questions:
- Data might be distributed in order to balance the workload.
- Data might be on the site where it was created for maintenance and security purposes.
- A client sends query to the closest database in order to minimized communication costs and increase throughput.
- In order to increase data availability in the event of system crashes.
It is remarkable to say that there are two main approaches to distributed data: replication and distribution of queries. In this article, I will cover on distribution of queries where each system manages a single copy of data, and uses distributed transaction mechanisms to access local and remote data. In this case, the distributed database looks like a collection of individual databases with its own schema. If the database systems are from different vendors, the system is referred to as heterogeneous, otherwise homogeneous.
Implementing distributed databases using SQL Server
Linked servers provide SQL Server the ability to access data from remote data sources. Using these mechanisms, you can issue queries, perform data modifications and execute remote procedures. You can use the T-SQL function OPENROWSET to query a remote data source without a linked server.
Let us now create a linked server to another SQL Server instance using the T-SQL procedure sp_addlinkedserver. The syntax of sp_addlinkedserver is shown in Listing 1:
- sp_addlinkedserver
- [ @server= ] 'server'
- [ ,[ @srvproduct= ] 'product_name'
- [ , [ @provider= ] 'provider_name'
- [ , [ @datasrc= ] 'data_source'
- [ , [ @location= ] 'location' ]
- [ , [ @provstr= ] 'provider_string'
- [ , [ @catalog= ] 'catalog' ]
And each parameter is described in table 1.
| Parameter | Description |
| server | Local name used for the linked server. |
| product_name | Product name of the OLE DB data source. For SQL Server instances, the product_name is 'SQL Server'. |
| provider_name | This is the unique programmatic identifier for the OLE DB provider. When not specified, the provider name is the SQL Server data source. The explicit provider_name for SQL Server is SQLNCLI (for Microsoft SQL Native Client OLE DB Provider). MSDAORA is used for Oracle, OraOLEDB.Oracle for Oracle versions 8 and higher, Microsoft.Jet.OLEDB.4.0 for MS Access and MS Excel, DB2OLEDB for IBM DB2, and MSDASQL for an ODBC data source. |
| data_source | This is the data source as interpreted by the OLE DB provider. |
| location | The location interpreted by the OLE DB provider. |
| provider_string | The connection string specific to the OLE DB provider. |
| catalog | This varies from the database systems. |
Table 1.
You can configure the linked server properties such as collection compatible, collation name, connect timeout and so on (for more information refer to the SQL Server online help) using the stored procedure sp_serveroption.
When executing a distributed query against a linked server, SQL Server maps your local login and credentials to the linked server. Based on the security on the remote data source, your credentials are accepted or rejected. By default, when a linked server is created, your local credentials are used to access data on the remote site. If you do not have the proper permission on the remote site, then your connection attempt is rejected. You can set up the mapping from your local login to any existing remote login using the stored procedure sp_addlinkedsrvlogin.
The syntax of this procedure is shown in Listing 2.
- sp_addlinkedsrvlogin [ @rmtsrvname = ] 'rmtsrvname'
- [ , [ @useself = ] 'useself' ]
- [ , [ @locallogin = ] 'locallogin' ]
- [ , [ @rmtuser = ] 'rmtuser' ]
- [ , [ @rmtpassword = ] 'rmtpassword' ]

Lionel LAWSON BODYPosted Aug 12, 2011, 12:25 PM
very clear information
Ali ObaidiPosted Aug 17, 2010, 4:56 PM
How do you run multiple distributed queries in parallel (@ same time)