现在的位置: 首页 > 综合 > 正文

一个游标的性能问题

2012年09月20日 ⁄ 综合 ⁄ 共 486字 ⁄ 字号 评论关闭

一个表大概有20来万记录

使用一个游标,当查询语句中用order by id

时速度齐慢,计划发现会做多个全表扫描,

 

后来采用 先添加到临时表,再做处理解决

------------------------速度很慢的sql-----------------

  Declare @DieA char(20)
Declare @DieB char(20)

Declare My_Cursor  cursor For
select isnull(ModuleID1,''),isnull(moduleId2,'') from product_auto_compjo
where batno='12017307' and barcode='15yuxinjie'
order by Id

open my_Cursor

Fetch My_Cursor
 Into @DieA,@DieB

While(@@Fetch_Status=0)
Begin
 --
 --Print @DieA + '|' +@DieB

 --处理下一条记录
 Fetch My_Cursor
 Into @DieA,@DieB
End

Close My_Cursor
deallocate My_cursor

抱歉!评论已关闭.