Procitao sam clanak koji je Chachka naveo. Tamo postoji sekcija "Cursor adventages" u koja pocinje sa:
Citat:
Cursors are best used when performing row-by-row operations that can't be accomplished with set-based operations (i.e., when you need to fire a stored procedure once per row in a table).
pa onda malo dalje
Citat:
Quick and dirty
SQL developers are often under the gun to write code fast. Writing a cursor requires less mental effort than writing its set-based equivalent. Unfortunately these shortcuts often remain in production and cause problems further down the line. (Thanks for the above two observations from SQL MVPs Itzik Ben Gan and Erland Sommarskog.)
Cursors are faster than using while loops.
Sekcija "Cursor Advantages" zavrsava se recenicom:
Citat:
With advantages like these, you may wonder what are the disadvantages of using cursors. Please, oh please, oh please keep reading.
Poslusam ih, citam dalje i usekciji 'Disadvantages' nadjem ovo:
Citat:
Cursors are frequently the wrong tool for the wrong task. They're used for quick-and-dirty programming when a developer does not have a good understanding of set operations -- or they're used for the wrong task entirely.
bas sam to hteo da kazem
Uocite u sekciji Advantages kaze se dva puta "Cursors are faster than using while loops". Tu i jeste problem. Dobar dizajn baze nema potrebu za nikakvim 'loops'. Ima situacija u zivotu kada se to ne moze izbeci, cak se ni Identity ne mogu izbeci uvek. To su izuzeci od kojih ne treba praviti pravilo. Znaci, staracka mudrost bi bila: izbegavaj kursore i identity kad god mozes. Sa brojem godina iskustva i starosti, smanjuje se broj situacija kada mislis da se mora koristiti kusrso i identity.
A ja nisam vise SQL programer, jer nikad nisam ni bio SQL programer. SQL nije program environment pa stoga ne postoji tako nesto - SQL programer. Postoje programeri u raznim jezicima, platformama i okruzenjima (web, DOS, Windows, .NET).
A programetre neko mora da kontrolise jer u najboljoj nameri naprave stetu. Losi programeri naprave malu stetu, veliku stetu naprave dobri programeri kad se umesaju u sta im nije posao - 'cursors - they're used for the wrong task entirely'