SQL 使用 Openquery 链接服务器更新表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14766520/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 13:33:22  来源:igfitidea点击:

Update table using Openquery linked server

sqlsql-serversql-server-2008tsqlopenquery

提问by Ivan G

I've tried this code and still got the following error, perhaps anyone could help?

我试过这段代码,但仍然出现以下错误,也许有人可以帮忙?

UPDATE a 
SET    a.MMDWNO = '21'
FROM   OPENQUERY(NMIIFLIB,
       'select * from MVXCDTANSN.MITMAS WHERE MMITTY = ''25''') a 

Error :

错误 :

OLE DB provider "MSDASQL" for linked server "NMIIFLIB" returned message "[IBM][iSeries Access ODBC Driver][DB2 UDB]SQL7008 - MITMAS in MVXCDTANSN not valid for operation.".
Msg 7343, Level 16, State 4, Line 1
The OLE DB provider "MSDASQL" for linked server "NMIIFLIB" could not UPDATE table "[MSDASQL]".

链接服务器“NMIIFLIB”的 OLE DB 提供程序“MSDASQL”返回消息“[IBM][iSeries Access ODBC 驱动程序][DB2 UDB]SQL7008 - MVXCDTANSN 中的 MITMAS 对操作无效。”。
消息 7343,级别 16,状态 4,第 1 行
链接服务器“NMIIFLIB”的 OLE DB 提供程序“MSDASQL”无法更新表“[MSDASQL]”。

The select statement works fine but when I try to update I always stuck with this.

select 语句工作正常,但是当我尝试更新时,我总是坚持这一点。

回答by Ivan G

If you're trying to update a table on linked server, try this syntax:

如果您尝试更新链接服务器上的表,请尝试以下语法:

UPDATE OPENQUERY(NMIIFLIB, 'select * from MVXCDTANSN.MITMAS where MMITTY = ''25''')
SET MMDWNO = 21

回答by Roushan Kumar

you must try this. Hope this will help you.

你必须试试这个。希望这会帮助你。

UPDATE OPENQUERY(firstlink, 'select * from job.dbo.student where id = ''3''') 
    SET name = 'sanjeev acharya'