用游标更新表,速度异常慢

eaglerxa 2008-06-23 11:40:15
AB表均为6w多条记录,用游标打开B,然后根据条件update A from B
居然10多分中还没完成。。。。。。不正常吧??
...全文
159 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
eaglerxa 2008-06-27
  • 打赏
  • 举报
回复
是啊,游标不知怎么回事
结果是用了很多次的update,一次次手动更新反倒更快,寒一个
ChinaITOldMan 2008-06-27
  • 打赏
  • 举报
回复
可以用批量更新,为什么要用cursor啊
灰太狼 2008-06-27
  • 打赏
  • 举报
回复
游标的效率太差了,能不用最好别用
liusaup 2008-06-27
  • 打赏
  • 举报
回复
此种场合使用游标当然效率低!能不使用游标就不要使用!
eaglerxa 2008-06-23
  • 打赏
  • 举报
回复
怎么这么乱

begin tran
declare cr cursor for select px, k, s, g, n, x from #tt
open cr
fetch next from cr into @Px, @k, @S, @g ,@n , @x
while @@fetch_Status = 0
begin
if @px = 1
begin
update kuan
set fs1 = @stone ,
fs1 = @Guig,
fs1 = @Num,
fs1 = @xiangf
where Temcode = @kuanh
end else
if @px =2
begin
update kuan
set fs2 = @stone ,
fs2 = @Guig,
fs2 = @Num,
fs2 = @xiangf
where Temcode = @kuanh
end else
if @px =3
。。。。。。。。。。。。。

fetch next from cr into @Px, @k, @S, @g ,@n , @x
end
commit tran
close cr
deallocate cr
eaglerxa 2008-06-23
  • 打赏
  • 举报
回复
大概如下:
begin tran
declare cr cursor for select px, k, s , g, n, x from #tt
open cr
fetch next from cr into @Px, @k, @S, @g ,@n , @x
while @@fetch_Status = 0
begin
if @px = 1
begin
update kuan
set fs1 = @stone ,
fs1 = @Guig,
fs1 = @Num,
fs1 = @xiangf
where Temcode = @kuanh
end else
if @px =2
begin
update kuan
set fs2e = @stone ,
fs2 = @Guig,
fs2 = @Num,
fs2 = @xiangf
where Temcode = @kuanh
end else
if @px =3
.......

fetch next from cr into @Px, @k, @S, @g ,@n , @x
end
commit tran
close cr
deallocate cr
eaglerxa 2008-06-23
  • 打赏
  • 举报
回复
大概如下:
begin tran
declare cr cursor for select px, k, s , g, n, x from #tt
open cr
fetch next from cr into @Px, @k, @S, @g ,@n , @x
while @@fetch_Status = 0
begin
if @px = 1
begin
update kuan
set fs1 = @stone ,
fs1 = @Guig,
fs1 = @Num,
fs1 = @xiangf
where Temcode = @kuanh
end else
if @px =2
begin
update kuan
set fs2e = @stone ,
fs2 = @Guig,
fs2 = @Num,
fs2 = @xiangf
where Temcode = @kuanh
end else
if @px =3
.......

fetch next from cr into @Px, @kuanh, @Stone, @guig,@num , @xiangf
end
commit tran
close cr
deallocate cr
wzy_love_sly 2008-06-23
  • 打赏
  • 举报
回复
case when不知道行不行,详细.
nzperfect 2008-06-23
  • 打赏
  • 举报
回复
这不好说,发语句吧.
ojuju10 2008-06-23
  • 打赏
  • 举报
回复

可以不用游标不?

批量更新!
nzperfect 2008-06-23
  • 打赏
  • 举报
回复
表kuan的Temcode加索引试试
create index idx_01 on kuan(Temcode)

22,298

社区成员

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

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