Discussion on:

5
Comments

Join the conversation!

Follow via:
RSS
Email Alert
0 Votes
+ -
You are not giving the whole story here. It may be true that the cursor performed less logical reads then the while loop however at what cost to CPU, memory, blocking and concurreny. In a highly concurrent OLTP system basing your choice on logical reads alone won't get you anywhere. Also how many logical scans did each do?
0 Votes
+ -
Everything else was the same besides the logical reads.

How would you have gone about comparing them?
I can't imagine a scenario where I should be using a cursor (e.g. iterating through a set of records) where I'd use a while loop, any potential performance gain (dubious at best in my opinion), would be totally offset by an increase in complexity and fragility.
Try to use a set based approach instead of a cursor is fine, a while loop?. Barking mad.....
Hey Tony,
Are you saying that you'd prefer to do a while loop over the cursor?
Tim
0 Votes
+ -
No
Tony Hopkinson 23rd Feb 2010
If I was operating on a recordset I'd use a cursor. If I was repeating an operation while some condition, then I'd use a while loop.

I'm also saying that if I can avoid using either I will.

I also can't see any worthwhile gain in using while instead of a cursor or vice versa, just going to confuse the hecik out of the poor chump who has to maintain it next. If a performance improvement was desirable I'd engineer out the loop or cursor. As far as I'm concerned swapping would either be correcting an error or a nasty hack.
Keyboard Shortcuts:
Prev
Next
Toggle
Join the conversation
Formatting +
BB Codes - Note: HTML is not supported in forums
  • [b] Bold [/b]
  • [i] Italic [/i]
  • [u] Underline [/u]
  • [s] Strikethrough [/s]
  • [q] "Quote" [/q]
  • [ol][*] 1. Ordered List [/ol]
  • [ul][*] · Unordered List [/ul]
  • [pre] Preformat [/pre]
  • [quote] "Blockquote" [/quote]

Join the TechRepublic Community and join the conversation! Signing-up is free and quick, Do it now, we want to hear your opinion.