• Igor Micev (3/14/2014)


    Luis Cazares (3/14/2014)


    Igor Micev (3/14/2014)


    Do you know that cursors' performance is nearly the same to the set-based statements when they are run on up to about 1000 rows.

    Not really, it might look that way with small sets of data, but it's mostly perception. A set based query will run several times faster than a cursor in most cases.

    It depends how many columns you're fetching into the cursor and what operations are then perform. However, for one or two columns and small number of rows I haven't seen significant differences. Once I was making some measures, and found out that number (1000) empiricallyl; but as I say, it depends.

    Yes, set-based is faster in any case.

    [/quote]

    It is the small number of rows that concerns me here. We don't generally design new processes against tables with millions of rows but we intend to use them there. And even if the table has only a couple hundred rows today, in the future it can grow to millions. Why write code that is just a time bomb? Your argument sounds like the pleas of somebody who was just asked why they wrote a cursor instead of set based solution. Just do it right the first time and then there is no need to worry about it.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/