When to use a cursor

  • Jeff Moden (4/1/2008)


    Ah ha! Finally! A challenge! If you would, post the resulting table creation script so I can duplicate what you have... the race is on! :w00t:

    Sent you an email Jeff. This should be interesting. 🙂

  • cjudge (4/1/2008)What you guys have to remember - and the above quote is perfect - is that the only reason you are managing the database is so that someone can use the data. In no way do I mean this to imply that the administrative/managerial tasks are not important. However, administration is "set-based" while using data is often record-based. There are countless examples:

    1. A piece of software must gather all new submissions (a record set) and step through the set (a cursor) presenting some data from the record (e.g. a suspect's photograph) to a human reviewer for review.

    2. A piece of software must find all records sharing some ID ( a record set) and then step through those records (a cursor) performing the instructions encoded in each record (e.g. probing remote sensors for current readings) and waiting for a return value before proceeding.

    etc.

    These all generalize to the following: A piece of software must perform an external process on each record in a record set.

    This is very true ... except the stepping process should be done client side using the results of a set-based query.

  • Exactly, Matt's hit the nail on the head. The data should be retrieved from the database as a set based query. The application can perform any looping or cursoring operations against a detached recordset where it is not impacting server resources. What concerns me is that the data is retrieved efficiently.

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

  • matt stockham (4/1/2008)


    This is very true ... except the stepping process should be done client side using the results of a set-based query.

    Absolutely spot on!

    --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)

  • SQLZ (4/1/2008)


    Jeff Moden (4/1/2008)


    Ah ha! Finally! A challenge! If you would, post the resulting table creation script so I can duplicate what you have... the race is on! :w00t:

    Sent you an email Jeff. This should be interesting. 🙂

    Outstanding... thanks Karl!

    --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)

Viewing 5 posts - 31 through 34 (of 34 total)

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