Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase «««2425262728

Cursors Be Gone! Expand / Collapse
Author
Message
Posted Wednesday, June 23, 2010 7:38 AM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Monday, September 8, 2014 11:08 AM
Points: 810, Visits: 2,134
Tom.Thomson (6/22/2010)
YSLGuru (6/21/2010)
[quote][b]Wow Tom, you really need to whip up on this guy bad ey? Is that he must confess that every word is his story is wrong and you are his SQL superior or what? I think its safe to say by now that everyone realizes what was intended and what is best when approaching the use of Cursors instead of some standard Set based methods to solve some unique problem. Are you done yet with beating up on this article and its author?

No, I don't need to whip up on Gaby, I'm well aware that he understands the issues as that's made clear by his response to comments made last year, when the \rtile was first published. But I do think it's very important that people don't start by asking "cursor or no cursor" but instead "set-oriented or row by row iterative" (as one can write row by row iteration in a single query without resorting to a cursor the distinction bewteen the two questions is non-trivial). The discussion so far doesn't really make that point clea. It's also important that on those rare occassions when the answer to that starting question is "iteration" people don't discard the cursor option in favour of inferior iterative methods like the temporary table one illustrated in the article - and (unless I've missed somethiong) only Hugo had commented on that, so I thought it would be useful to make the two points together in one comment.
If Gaby thinks I was whipping up oon him I'm sure he'll let me know and if he does I will apologise profusely since that is certainly not an impression I wanted to give him.


Hi folks, it's all good, no harm done, but I am a little older and wiser in this regard. I've submitted a preamble to the article (left the article intact as that was what generated so much conversation in the first place) and hopefully it should get updated soon. Cheers.


Gaby
________________________________________________________________
"In theory, theory and practice are the same. In practice, they are not."
- Albert Einstein
Post #941743
Posted Wednesday, June 23, 2010 7:47 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Monday, October 22, 2012 8:55 AM
Points: 124, Visits: 180
Having read through umpteen threads on here like this, I think that every article on SSC should have a disclaimer:

"All concepts, views, and results in this Article are as shown in good faith by the author. They may not be applicable to your situation, servers or configuration, and may in fact prove detrimental in certain border cases. Your mileage may vary. Your house may be repossessed if you do not keep up your mortgage repayments. If you have any empirical evidence of cases where this method is worse than than the obvious solution, please post them with results."


:^)
Post #941751
Posted Friday, December 24, 2010 2:41 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, June 13, 2012 2:48 AM
Points: 5, Visits: 21
I agree that cursors are a drag on performance but what a way to go about avoiding them! A Count(*) and a delete for every row of the table, REALLY?

You can achieve the same effect far more efficiently by declaring a temporary table with an Identity column as Primary Key. Then all you need to do is increment a variable and do select where Id = @Iterator, you can test @@Rowcount or value IS NULL to manage the loop.
Post #1039062
« Prev Topic | Next Topic »

Add to briefcase «««2425262728

Permissions Expand / Collapse