How to get optimum performance when using 'for update' cursor?
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.
精彩评论