事务复制时产生的存储过程是否有问题?

WhiteEat 2005-08-03 11:00:05
对NorthWind 的 Products表做事务复制,在更新了某个字段以后(比如:ReorderLevel),复制过程总是对ProductID也进行更新,导致出现无法更新标示列ProductID的错误,查了以下存储过程,发现是复制过程错误的认为ProductID需要更改,实在郁闷?请高手指教其中的原因。
存储过程是这样的:
create procedure "sp_MSupd_Products"
@c1 int,@c2 nvarchar(40),@c3 int,@c4 int,@c5 nvarchar(20),@c6 money,@c7 smallint,@c8 smallint,@c9 smallint,@c10 bit,@pkc1 int
,@bitmap binary(2)
as
if substring(@bitmap,1,1) & 1 = 1
begin
update "Products" set
"ProductID" = case substring(@bitmap,1,1) & 1 when 1 then @c1 else "ProductID" end
,"ProductName" = case substring(@bitmap,1,1) & 2 when 2 then @c2 else "ProductName" end
,"SupplierID" = case substring(@bitmap,1,1) & 4 when 4 then @c3 else "SupplierID" end
,"CategoryID" = case substring(@bitmap,1,1) & 8 when 8 then @c4 else "CategoryID" end
,"QuantityPerUnit" = case substring(@bitmap,1,1) & 16 when 16 then @c5 else "QuantityPerUnit" end
,"UnitPrice" = case substring(@bitmap,1,1) & 32 when 32 then @c6 else "UnitPrice" end
,"UnitsInStock" = case substring(@bitmap,1,1) & 64 when 64 then @c7 else "UnitsInStock" end
,"UnitsOnOrder" = case substring(@bitmap,1,1) & 128 when 128 then @c8 else "UnitsOnOrder" end
,"ReorderLevel" = case substring(@bitmap,2,1) & 1 when 1 then @c9 else "ReorderLevel" end
,"Discontinued" = case substring(@bitmap,2,1) & 2 when 2 then @c10 else "Discontinued" end
where "ProductID" = @pkc1
if @@rowcount = 0
if @@microsoftversion>0x07320000
exec sp_MSreplraiserror 20598
end
else
begin
update "Products" set
"ProductName" = case substring(@bitmap,1,1) & 2 when 2 then @c2 else "ProductName" end
,"SupplierID" = case substring(@bitmap,1,1) & 4 when 4 then @c3 else "SupplierID" end
,"CategoryID" = case substring(@bitmap,1,1) & 8 when 8 then @c4 else "CategoryID" end
,"QuantityPerUnit" = case substring(@bitmap,1,1) & 16 when 16 then @c5 else "QuantityPerUnit" end
,"UnitPrice" = case substring(@bitmap,1,1) & 32 when 32 then @c6 else "UnitPrice" end
,"UnitsInStock" = case substring(@bitmap,1,1) & 64 when 64 then @c7 else "UnitsInStock" end
,"UnitsOnOrder" = case substring(@bitmap,1,1) & 128 when 128 then @c8 else "UnitsOnOrder" end
,"ReorderLevel" = case substring(@bitmap,2,1) & 1 when 1 then @c9 else "ReorderLevel" end
,"Discontinued" = case substring(@bitmap,2,1) & 2 when 2 then @c10 else "Discontinued" end
where "ProductID" = @pkc1
if @@rowcount = 0
if @@microsoftversion>0x07320000
exec sp_MSreplraiserror 20598
end

GO
...全文
83 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
WhiteEat 2005-08-03
  • 打赏
  • 举报
回复
这个方法是可以,但是微软的这个存储过程为何会错误识别用户的动作呢,事实上ProductID

并不需要Update,为何不会调用下一个else的代码?
hisi 2005-08-03
  • 打赏
  • 举报
回复
事务复制不要把identity属性传到订阅服务器

22,207

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧