From the course: SQL Server Performance for Developers

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Why while loops are cursors

Why while loops are cursors - SQL Server Tutorial

From the course: SQL Server Performance for Developers

Start my 1-month free trial

Why while loops are cursors

- [Instructor] In talking talking about set versus real based operations, one common myth we run into is that WHILE loops may be faster than cursors or they operate very differently than cursors. And this simply just isn't the case. The only real advantage WHILE loops have over cursors in SQL server is that the code is a little bit simpler to run. But let's talk about of the myths that are associated with these comparisons. Its fairly common if you read internet forums on SQL or Stack overflow that you'll see that instead of doing a cursor, a developer will frequently say, hey, I'll do a WHILE loop cause I've heard cursors are bad and surely WHILE loops are faster. A couple of examples here, some common sentiments that WHILE loops will perform better than cursors and that's simply not true. The performance and the functionality and the operations that are taking place under the hood are really the same. And another example is the code is easier to write than a cursor. That may be the…

Contents