After you create a new connection server on SQL Server
Executes the specified pass-through query on the specified linked server.The server is an OLE DB data source.OPENQUERY can be referenced in the FROM clause of a query as if it were a table name. OPENQUERY can also be referenced as the target table for an INSERT, UPDATE, or DELETE statement. However, this depends on the functionality of the OLE DB access interface. Although the query may return more than one result set, OPENQUERY returns only the first one.
Transact-SQL syntax Conventions
Grammar Copy
OPENQUERY (linked_server, ' query ')
Parameters
- Linked_server
-
Represents the identifier for the linked server name.
-
' query
'
-
The query string executed in the linked server. the maximum length of the string is 8 KB.
Notes
OPENQUERY A variable that does not accept its arguments.
OPENQUERY cannot be used to perform extended stored procedures on linked servers. However, you can execute an extended stored procedure on a linked server by using the four-part name. For example:
EXEC SeattleSales.master.dbo.xp_msver
Any call to OpenDataSource, OPENQUERY, or OPENROWSET in the FROM clause is calculated separately from any calls to those functions that are used as the update target, even if the same arguments are supplied for the two calls. specifically, filters or join conditions that apply to the results of any of these calls do not affect the results of other calls.
Permissions
Any user can execute OPENQUERY. The permissions used to connect to the remote server are obtained from the settings defined for the linked server.
Example A. Executing an UPDATE pass-through query
The following example uses the UPDATE delivery query for the linked server created in example A .
UPDATE OPENQUERY (oraclesvr, ' SELECT name from joe.titles WHERE id = 101 ') SET name = ' Adifferentname ';
B. Performing an INSERT pass-through query
The following example uses the INSERT pass-through query for the linked server created in example A .
INSERT OPENQUERY (oraclesvr, ' SELECT name from Joe.titles ') VALUES (' Newtitle ');
C. Executing a DELETE pass-through query
The following example uses a delete pass query to delete rows inserted in example C.
DELETE OPENQUERY (oraclesvr, ' SELECT name ' from joe.titles WHERE name = ' Newtitle ');
SQL Server remote access to Oracle database