Next week as part of the free SQL Query training that Aaron Buma and I provide, the topic I will be presenting is cursors. How to use them, what they are, everything you ever wanted to know.
My concern in this presentation is that cursors have caused me many headaches in regard to performance over time.
The main problem that I see is that developers who generally think in programming constructs like looping, like to use cursors because it is comfortable, it is more like a WHILE loop iterating through a result set. But SQL Server is designed manage sets of data through joining very quickly, and iterating through a loop generally ends up being much slower that joining. The term RBAR or Row By Agonizing Row describes this slow process.
I am looking for other arguments as to why cursors are good or bad. I know the final answer is always, “It Depends”, but what are some cases that cursors work well, and what are areas that they are horrible? I am looking for some stories here to help provide a good foundation for the weekly training.
Please post your response below.