Re: Cursor for loops
From: Ian Oldbury (ian_oldbury_at__NO_msn_SPAM_.com)
Date: 10/13/04
- Next message: Dex Dexter: "msi push install upgrade"
- Previous message: Abdul Hameed: "Transfer Partial data from one SQL Server to another Server"
- In reply to: David Portas: "Re: Cursor for loops"
- Next in thread: Arun: "Re: Cursor for loops"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 13 Oct 2004 16:22:49 +0100
lots to think about there thanks david
"David Portas" <REMOVE_BEFORE_REPLYING_dportas@acm.org> wrote in message
news:88FD9FB0-AFA2-4DC6-883E-9AD8C99B6CCF@microsoft.com...
> I'd estimate that for most people using SQL Server at least 99.99% of data
> manipulation can be done without a cursor. Inevitably there are inherently
> procedural tasks that are not regular data manipulation and these are what
> I
> would call acceptable uses of a cursor. I'm talking about things like
> sending
> emails and automated management processes such as monitoring databases,
> updating statistics, rebuilding indexes, managing backups, etc.
>
> Sometimes operational constraints (as distinct from technical ones) may
> compel you to use a cursor where you might be better off without. For
> example
> some existing code in a stored procedure that needs to be invoked for each
> row of a set and where you haven't the remit or the resources to rewrite
> that
> SP.
>
> There is also a relatively small class of tasks which don't have feasible
> set-based solutions but where a cursor proves more efficient. These are
> rare
> in my experience although one or two examples have been discussed in this
> group and elsewhere. If you think you have encountered one of these then
> always get a second opinion. Post the problem here if you like.
>
> Finally there is what anecdotal evidence suggests is by far the most
> common
> use of a cursor: those written by developers familiar with procedural
> languages who don't know SQL well enough to write effective set-based
> code.
> There are lots of examples of these. Unfortunately this code is usually
> inefficient, doesn't scale well and is often very costly to support and
> maintain. As a guide, I haven't written a single cursor for an actual
> data-manipulation task in the last 5 years. So if you are writing curors
> (except for admin-type tasks) regularly then you should certainly think
> again
> about whether your code is as efficient, reliable and maintainable as it
> ought to be.
>
> --
> David Portas
> SQL Server MVP
> --
>
- Next message: Dex Dexter: "msi push install upgrade"
- Previous message: Abdul Hameed: "Transfer Partial data from one SQL Server to another Server"
- In reply to: David Portas: "Re: Cursor for loops"
- Next in thread: Arun: "Re: Cursor for loops"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|