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 ««12

Are cursors hard on servers? Expand / Collapse
Author
Message
Posted Friday, May 23, 2014 11:32 AM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Yesterday @ 12:11 PM
Points: 308, Visits: 812
I would take a cursor over a triangular join if I was reporting on a running total in a columns. That's once instance.
Post #1574166
Posted Friday, May 23, 2014 12:43 PM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Today @ 2:20 PM
Points: 3,332, Visits: 7,187
MMartin1 (5/23/2014)
I would take a cursor over a triangular join if I was reporting on a running total in a columns. That's once instance.

That's ok if you can't (or don't want to) use the quirky update or the windowing functions available on 2012 and 2014.



Luis C.
I am a great believer in luck, and I find the harder I work the more I have of it. Stephen Leacock

Forum Etiquette: How to post data/code on a forum to get the best help
Post #1574199
Posted Friday, May 23, 2014 5:32 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 11:31 AM
Points: 36,728, Visits: 31,180
Eirikur Eiriksson (4/1/2014)
Most of the time cursors can be avoided but it's not a religion, there are tasks which do justify the use of cursors. Obviously if an operation can be achieved using a set based methods, it fits the environment better. But some things like one off operations, continued operation where there are serious exceptions and so forth might justify it. All boils down to "it depends".

To answer the question if cursors are hard on the servers, "it depends".


To add to that, there are a whole lot of people who simply think certain tasks "justify the use of cursors" because they just don't know differently and that frequently results in the inappropriate use of Cursors and other RBAR. A great and prominent example of this is the number of people that STILL post "splitters" with WHILE Loops and rCTEs.

As for "Continued Operation where there are serious exceptions", I suggest that using cursors in such a fashion should be replaced by prevalidating data whenever possible... and it's normally possible. To coin a phrase, "There should be no expected failures."


--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1574268
Posted Friday, May 23, 2014 5:37 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 11:31 AM
Points: 36,728, Visits: 31,180
MMartin1 (5/23/2014)
I would take a cursor over a triangular join if I was reporting on a running total in a columns. That's once instance.


A fairly rare exception, indeed. Of course, I wouldn't use either even if I needed to work with something less than 2K12.


--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1574269
« Prev Topic | Next Topic »

Add to briefcase ««12

Permissions Expand / Collapse