SQL uses OpenQuery for cross-Library operations

Source: Internet
Author: User
Tags ole

Excerpt from: http://www.cnblogs.com/aji88/archive/2009/11/06/1597263.html

Executes the specified pass-through query on the given 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
(, 'query')
Parameters

HTTP://DDUE.SCHEMAS.MICROSOFT.COM/AUTHORING/2003/5 NS = "HTTP://DDUE.SCHEMAS.MICROSOFT.COM/AUTHORING/2003/5"

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.

Note

OPENQUERY A variable that does not accept its arguments.

In SQL Server 2000 and later versions, 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
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 a SELECT pass-through query

The following example uses the Microsoft provider for Oracle to create a linked server named for the Oracle database OracleSvr . The example then uses the pass-through query for this linked server SELECT .

Attention:

This example assumes ORCLDB that an Oracle database alias named is already created.

' Oraclesvr ',    ' Oracle 7.3 ',    ' Msdaora ',    ' orcldb 'goSELECT *go   
B. Executing an UPDATE pass-through query

The following example uses a pass-through query for the linked server created in example A UPDATE .

' Adifferentname ';
C. Performing an INSERT pass-through query

The following example uses a pass-through query for the linked server created in example A INSERT .

' SELECT name from Joe.titles ')VALUES (' newtitle '); 
D. Executing a DELETE pass-through query

The following example uses DELETE a pass-through query to delete rows inserted in example C.

' SELECT name from joe.titles WHERE name = 'newtitle '); 

SQL uses OpenQuery for cross-Library operations

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.