Sql server 更新Transact-SQL链接表时出错,影响的行太多
我正在尝试用此更新链接表Sql server 更新Transact-SQL链接表时出错,影响的行太多,sql-server,tsql,sql-update,linked-server,Sql Server,Tsql,Sql Update,Linked Server,我正在尝试用此更新链接表 update openquery (LINKSERVERID, 'select tng_email from user_list where tng_id = 62873') set tng_email = 'blah@blah.com'; 。。。但我得到以下错误 链接服务器“LINKSERVERID”的OLE DB提供程序“MSDASQL”返回消息“键列信息不足或不正确”。 受更新影响的行太多。“ 仅供参考:tng_id是主键 我怎么修理 我认为您需要在sel
update openquery (LINKSERVERID, 'select tng_email from user_list where tng_id = 62873')
set tng_email = 'blah@blah.com';
。。。但我得到以下错误
链接服务器“LINKSERVERID”的OLE DB提供程序“MSDASQL”返回消息“键列信息不足或不正确”。
受更新影响的行太多。“
仅供参考:tng_id
是主键
我怎么修理 我认为您需要在select查询中包含该键,因此请尝试以下操作:
update openquery(
LINKSERVERID, 'select tng_id, tng_email from user_list where tng_id = 62873'
) set tng_email = 'blah@blah.com';
我尝试了jpw上面的答案,但对我无效 我开发了一个触发器,使用下面的代码我也收到了相同的错误:
begin
if TRIGGER_NESTLEVEL() > 1
return
declare @JCid int = (select top 1 iJCMasterID from inserted)
begin
update L set uiJCTxCMLineNumber = NewLineNum
from (
select
rank() over (order by idJCTxLines) NewLineNum
, iJCMasterID
, uiJCTxCMLineNumber
, idJCTxLines
from _btblJCTxLines
where iJCMasterID = @JCid
) L
where iJCMasterID = @JCid
end
end
go
但是,我将其更改为:
begin
if TRIGGER_NESTLEVEL() > 1
return
declare @JCid int = (select top 1 iJCMasterID from inserted)
begin
update L set uiJCTxCMLineNumber = NewLineNum
from (
select
rank() over (order by idJCTxLines) NewLineNum
, iJCMasterID
, uiJCTxCMLineNumber
, idJCTxLines
from _btblJCTxLines
where iJCMasterID = @JCid
) L
join inserted i on L.idJCTxLines = i.idJCTxLines
end
end
go
希望这有帮助。我通过向基础表添加唯一索引解决了此错误