|
Posted by Erland Sommarskog on 06/18/05 00:49
(chrisandkayenolan@gmail.com) writes:
> Cursors are a bad idea to use as they hold locks on tables for their
> duration. They are also not necessary as you can use set rowcount 1 to
> loop through records individually.
SET ROWCOUNT 1 is probably the worst form of iteration you can do. That
was what we did back in 4.x days, and it was no fun at all. When you
need to iterate, cursors are indeed the way to do.
Whether cursors hold locks or not, depends on what sort of cursor
you use. The default cursor type is a keyset cursor, a creature I
have never fully understood. Add INSENSITIVE before CURSOR, and you
don't have to worry. The result set for the cursor is fixed once
for all.
--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinfo/productdoc/2000/books.asp
Navigation:
[Reply to this message]
|