Home Forums SQL Server 7,2000 T-SQL Cursors - need to help to explain why to not use them RE: Cursors - need to help to explain why to not use them

  • Yes as mentioned, try to avoid believing that cursors are always bad. Sometimes their performance can be as good as, if not better than other approaches. However, when using them you really should try to explore other ways of doing things as more often than not, they're not really required.

    I think the main problem with cursors is that they present a certain way of thinking. That way of thinking for some people can be easier to visualise than other approaches. However, many times there is a set based solution to what the cursor is being used for. I think the best analogy I've heard is to think of the task of putting sugar in a coffee. You can use a pair of tweezers and take one grain at a time or you can use a tea spoon and do it in one go. You want to make sure you select the tea spoon approach. The tweezer approach might be technically correct but you're leaking performance. So when using a cursor see whether you can do bulk processing on the records you are feeding into your cursor rather than against each record in turn.