Last Update: 12 May 2009
Product: StarSQL
Version: 5.x
Article ID: SQV00SQ004
SQL Server linked servers can be used to access DB2 through a StarSQL ODBC data source. This document demonstrates how to add and use a linked server. These instructions apply to SQL Server 7, SQL Server 2000, SQL Server 2005, and SQL Server 2008.
Perform the following steps to configure, test, and use a linked server.
StarSQL (64-bit) users should review the StarQuest Technical Document Considerations for using StarSQL (64-bit) with SQL Server 2005/2008.
If an error occurs while testing the linked server connection, review the error and make changes to the linked server configuration as necessary.
In the Enterprise Manager, expand the new linked server and click on Tables to display a table list.
In the Management Studio, click on the New Query button and execute a query using the samples below as a guideline.
In the Management Studio, expand the linked server node and then expand the Catalogs node. Click on the node for the linked server and expand the Tables to view a table list.
The following examples demonstrate how to use a linked server to execute SELECT, INSERT, UPDATE, and DELETE statements. Execute these statements in either the SQL Server 7/2000 Query Analyzer or the SQL Server 2005/2008 New Query field. These examples assume the following:
To perform a SELECT on the table:
SELECT * FROM STARSQLDSN.<catalog>.BOOKS.TITLES
OR
SELECT * FROM OPENQUERY (STARSQLDSN, 'SELECT * FROM BOOKS.TITLES')
To INSERT a row into the table:
INSERT INTO STARSQLDSN.<catalog>.BOOKS.TITLES (TITLE) VALUES ('The Grapes of Wrath')
OR
INSERT INTO OPENQUERY (STARSQLDSN, 'SELECT * FROM BOOKS.TITLES') (TITLE) VALUES ('The Grapes of Wrath')
To UPDATE a row in the table:
UPDATE STARSQLDSN.<catalog>.BOOKS.TITLES SET TITLE = 'Of Mice and Men' WHERE TITLE = 'The Grapes of Wrath'
OR
UPDATE OPENQUERY (STARSQLDSN, 'SELECT * FROM BOOKS.TITLES') SET TITLE = 'Of Mice and Men' WHERE TITLE = 'The Grapes of Wrath'
To DELETE a row in the table:
DELETE STARSQLDSN.<catalog>.BOOKS.TITLES WHERE TITLE = 'The Grapes of Wrath'
OR
DELETE OPENQUERY (STARSQLDSN, 'SELECT * FROM BOOKS.TITLES') WHERE TITLE = 'The Grapes of Wrath'
NOTES:
If the table being accessed has an index defined on more than 16 columns, you may receive this error message:
OLE DB provider "MSDASQL" for linked server "<linkedserver>" returned an invalid index definition for table ""<catalog>"."<schema>"."<tablename>"".As a workaround, either use the OPENQUERY syntax to query this table or remove the offending index. Refer to the "Maximum Capacity Specifications for SQL Server" section of the SQL Server Books Online for more information.
The information in technical documents comes without any warranty or applicability for a specific purpose. The author(s) or distributor(s) will not accept responsibility for any damage incurred directly or indirectly through use of the information contained in these documents. The instructions may need to be modified to be appropriate for the hardware and software that has been installed and configured within a particular organization. The information in technical documents should be considered only as an example and may include information from various sources, including IBM, Microsoft, and other organizations.