0

Possible Duplicate:
What is wrong with Cursors ?

Why we say cursor will affect the performance. Even we use some other looping instead of cursors it works similarly right? Please advise

Community
  • 1
  • 1
Bala
  • 1,386
  • 1
  • 14
  • 27
  • 4
    **TONS** of duplicates - e.g. [What is wrong with Cursors ?](http://stackoverflow.com/questions/743183/what-is-wrong-with-cursors) - please **search** first before asking a question over and over and over again - thanks. – marc_s Sep 09 '10 at 11:29
  • Thanks for redirecting me to the answer, Marc – Bala Sep 09 '10 at 11:31
  • 1
    http://wiki.lessthandot.com/index.php/Cursors_and_How_to_Avoid_Them – HLGEM Sep 09 '10 at 13:12

4 Answers4

0

If your SQL is designed to work RBAR (Row-by-agonizing-row) then a Loop or Cursor will take a long time.

SQL is best with set data, work with sets instead of rows and your performance will generally increase.

If you rephrase your question or post some example SQL, we might be able to help more!

Russ Clarke
  • 17,511
  • 4
  • 41
  • 45
0

Have a look at Performance Tuning SQL Server Cursors

Adriaan Stander
  • 162,879
  • 31
  • 289
  • 284
0

Not really sure what the question is, but cursors are indeed dramatically sluggish on SQL Server when used on a row-2-row basis;

Post some specific code or question.

riffnl
  • 3,248
  • 1
  • 19
  • 32
0

because databases work on sets not on looping. it is much faster to do this

update table set SomeCol = 'A'
where SomeDAte > '2010-01-01'

than writing a cursor and update this row by row

The only time I use cursors is if I have to do some maintenance like rebuilding or reorganizing an index

SQLMenace
  • 132,095
  • 25
  • 206
  • 225