Best Replaces for Cursor

  • As you know, using cursor in stored procedure, etc. links to performance problem. Is there any article describing all situation in which something else can be used instead of cursors?

  • I highly recommend an article by Jeff Moden

    http://www.sqlservercentral.com/articles/TSQL/62867/

    If you really want to get into the depths of replacing a cursor follow this forum here on SSC

    http://www.sqlservercentral.com/Forums/Topic695508-338-1.aspx

    If everything seems to be going well, you have obviously overlooked something.

    Ron

    Please help us, help you -before posting a question please read[/url]
    Before posting a performance problem please read[/url]

  • The answer is..."it depends!"

    Sometimes, a cursor *is* the optimal solution. Not often, but it does happen.

    If you tell us a little more background to your question, you may get a better answer!

    P.S. It helps if you can show what your thoughts are, and why.

    Cheers

    Paul

  • Paul White

    The answer is..."it depends!"

    Sometimes, a cursor *is* the optimal solution. Not often, but it does happen.

    Paul care to post some code that shows an example of where a cursor solution is better than a set based solution?

    If everything seems to be going well, you have obviously overlooked something.

    Ron

    Please help us, help you -before posting a question please read[/url]
    Before posting a performance problem please read[/url]

  • Removed as confusing to too many

    If everything seems to be going well, you have obviously overlooked something.

    Ron

    Please help us, help you -before posting a question please read[/url]
    Before posting a performance problem please read[/url]

  • Here[/url]'s the first article in an on-going series on that very subject (by me). The discussion attached to it gets pretty deeply into it also.

    [font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
    Proactive Performance Solutions, Inc.
    [/font]
    [font="Verdana"] "Performance is our middle name."[/font]

  • Thank you RBarryYoung.

    @Bitbucket: Please note that Paul Neilsen and I are different people. There is a clue in my surname.

    The example that springs to mind is where a stored procedure needs to be called to process an input set row-by-row. A good many real-world applications have this requirement somewhere. In principle, one might be able to replace the legacy code and cursor with a fully set-based solution, but (a) I don't think that's provably true; and (b) life is way too short.

    Cheers,

    Paul

  • I have to admit, I found that very confusing.

    [font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
    Proactive Performance Solutions, Inc.
    [/font]
    [font="Verdana"] "Performance is our middle name."[/font]

  • It's gone now.

    I didn't even try to understand it.

  • bitbucket (4/19/2009)


    Paul White

    The answer is..."it depends!"

    Sometimes, a cursor *is* the optimal solution. Not often, but it does happen.

    Paul care to post some code that shows an example of where a cursor solution is better than a set based solution?

    Any situation where a set-based solution CANNOT be used. One example is where you need to call multiple sets of sprocs with inputs from a single row and those sprocs cannot be disassembled to combine into some potential set-based solution.

    Best,
    Kevin G. Boles
    SQL Server Consultant
    SQL MVP 2007-2012
    TheSQLGuru on googles mail service

  • TheSQLGuru (4/20/2009)


    Any situation where a set-based solution CANNOT be used. One example is where you need to call multiple sets of sprocs with inputs from a single row and those sprocs cannot be disassembled to combine into some potential set-based solution.

    Me - some posts earlier!


    The example that springs to mind is where a stored procedure needs to be called to process an input set row-by-row. A good many real-world applications have this requirement somewhere. In principle, one might be able to replace the legacy code and cursor with a fully set-based solution, but (a) I don't think that's provably true; and (b) life is way too short.

    Spooky!

    :laugh:

  • Great minds think alike! 😎

    Best,
    Kevin G. Boles
    SQL Server Consultant
    SQL MVP 2007-2012
    TheSQLGuru on googles mail service

  • TheSQLGuru (4/20/2009)


    Great minds think alike! 😎

    Speak for yourself! I pride myself on having a rather average mind :laugh:

  • :laugh: :laugh: :laugh:

    thanks all for your comments!

    actually,I'm DBA ( a novice one 😛 ) and we usually have performance problem in our servers> I've decided to send all developer, general comments about when to use cursor and when replace cursor with something else. by the way, I'll read those articles carefully

Viewing 14 posts - 1 through 13 (of 13 total)

You must be logged in to reply to this topic. Login to reply