开发者

How to get optimum performance when using 'for update' cursor?

开发者 https://www.devze.com 2023-04-03 08:49 出处:网络
Which is a better choice of update a record in cursor \"mode\" ? FETCH NEXT FROM my_cur INTO @Param_Id

Which is a better choice of update a record in cursor "mode" ?

FETCH NEXT FROM my_cur INTO @Param_Id     
      WHILE @@FETCH_STATUS = 0 
            BEGIN 
                      ...
    开发者_StackOverflow社区                  UPDATE MyTable
                      SET    name= 'aaa'
                      WHERE  MyTable.id = @Param_Id  // update the regular TABLE ...
                      ...
            END

or with

WHERE CURRENT OF my_cur // update the current cursor row

what is the difference?

(Cursors are required in this particular case).


I would imagine WHERE CURRENT OF ... would have underlying optimizations for it instead of needing to find the row again for the nested UPDATE re-selecting on a Candidate Key.

The semantics may also slight different -- imagine if id was NOT a Candidate Key.

It would be nice to see some results of some real-world tests as it might show a clear advantage one way or another.

Happy coding.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号