使用动态值更新远程视图会引发错误
Updating remote view with dynamic value throws an error
我有一个 updatable 视图 (vwItem) 正在通过链接服务器访问 ([sql\dev].)
当我用静态数据更新视图时,基础 table 会更新。
UPDATE ci SET CertifiedNumber = '44444'
FROM [sql\dev].contact.dbo.vwItem ci WITH (NOLOCK)
WHERE ci.CertifiedBatchID IN ( 5829 )
但是当我尝试传递动态值时,
declare @lo_vch_CertifiedNumber varchar(50) =
'1111111111222222222233333'
UPDATE ci
SET CertifiedNumber = @lo_vch_CertifiedNumber + '44444'
FROM [sql\dev].contact.dbo.vwItem ci
WITH (NOLOCK)
WHERE ci.CertifiedBatchID IN ( 5829 )
失败,出现以下错误消息
The statement has been terminated.
Msg 16932, Level 16, State 1,
Line 1
The cursor has a FOR UPDATE list and the requested column
to be updated is not in this list.
我什至不使用游标,但错误中提到了游标..
这里是"vwItem"的定义。
CREATE view [dbo].vwItem
with schemabinding
AS
select CertifiedItemID = cast(CertifiedItemID as varchar),
CertifiedNumber, [Service], Weight, Price, CertifiedBatchID
from dbo.tblItem (nolock)
为什么会出现错误,这是什么意思?
通过实现更新 vwItem 的存储过程而不是使用可更新视图解决了这个问题
我有一个 updatable 视图 (vwItem) 正在通过链接服务器访问 ([sql\dev].)
当我用静态数据更新视图时,基础 table 会更新。
UPDATE ci SET CertifiedNumber = '44444'
FROM [sql\dev].contact.dbo.vwItem ci WITH (NOLOCK)
WHERE ci.CertifiedBatchID IN ( 5829 )
但是当我尝试传递动态值时,
declare @lo_vch_CertifiedNumber varchar(50) = '1111111111222222222233333'
UPDATE ci
SET CertifiedNumber = @lo_vch_CertifiedNumber + '44444'
FROM [sql\dev].contact.dbo.vwItem ci WITH (NOLOCK)
WHERE ci.CertifiedBatchID IN ( 5829 )
失败,出现以下错误消息
The statement has been terminated.
Msg 16932, Level 16, State 1, Line 1
The cursor has a FOR UPDATE list and the requested column to be updated is not in this list.
我什至不使用游标,但错误中提到了游标..
这里是"vwItem"的定义。
CREATE view [dbo].vwItem
with schemabinding
AS
select CertifiedItemID = cast(CertifiedItemID as varchar),
CertifiedNumber, [Service], Weight, Price, CertifiedBatchID
from dbo.tblItem (nolock)
为什么会出现错误,这是什么意思?
通过实现更新 vwItem 的存储过程而不是使用可更新视图解决了这个问题