Executes the specified pass-through query on the given linked server, which is an OLE DB data source. The OPENQUERY function can be referenced in the FROM clause of a query as though it is a table name. The OPENQUERY function can also be referenced as the target table of an INSERT, UPDATE, or DELETE statement, subject to the capabilities of the OLE DB provider. Although the query may return multiple result sets, OPENQUERY returns only the first one.
OPENQUERY(linked_server, 'query')
This example creates a linked server named OracleSvr against an Oracle database using the Microsoft OLE DB Provider for Oracle. Then this example uses a pass-through query against this linked server.
Note This example assumes that an Oracle database alias called ORCLDB has been created.
EXEC sp_addlinkedserver 'OracleSvr',
'Oracle 7.3’,
'MSDAORA',
'ORCLDB'
GO
SELECT *
FROM OPENQUERY(OracleSvr, 'SELECT name, id FROM joe.titles')
GO
DELETE | sp_addlinkedserver |
Distributed Queries | sp_serveroption |
FROM | UPDATE |
INSERT | WHERE |
OPENROWSET | Rowset Functions |
SELECT |