OpenQuery usage

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了OpenQuery usage相关的知识,希望对你有一定的参考价值。

Executes the specified pass-through query on the specified linked server. This 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 of an INSERT, UPDATE, or DELETE statement. This is subject to the capabilities of the OLE DB provider. Although the query may return multiple result sets, OPENQUERY returns only the first one.

 

Openquery 函数是不确定性的函数,就是说,对于相同的输入值,不保证每次返回的值都是相同的。

All rowset functions are nondeterministic. This means these functions do not always return the same results every time they are called, even with the same set of input values.

 

一,Syntax

OPENQUERY ( linked_server ,query )

Any call to OPENDATASOURCE, OPENQUERY, or OPENROWSET in the FROM clause is evaluated separately and independently from any call to these functions used as the target of the update, even if identical arguments are supplied to the two calls. In particular, filter or join conditions applied on the result of one of those calls have no effect on the results of the other.

 

二,Examples

1,Executing an UPDATE pass-through query

UPDATE OPENQUERY (OracleSvr, SELECT name FROM joe.titles WHERE id = 101) 
SET name = ADifferentName;

2,Executing an INSERT pass-through query

INSERT OPENQUERY (OracleSvr, SELECT name FROM joe.titles)
VALUES (NewTitle);

3,Executing a DELETE pass-through query

DELETE OPENQUERY (OracleSvr, SELECT name FROM joe.titles WHERE name = ‘‘NewTitle‘‘‘);

 

参考文档: MSDN OPENQUERY (Transact-SQL)

以上是关于OpenQuery usage的主要内容,如果未能解决你的问题,请参考以下文章

[linux][c/c++]代码片段01

使用 Openquery 链接服务器更新表

SQL: OPENQUERY 问题

SQL 使用openquery进行跨库操作

带有 OpenQuery 和参数的 NativeQuery

MS SQL - MySQL - Openquery 中文字符导入为“?”