• 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.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)