Posted by David Portas on 02/17/06 14:29
vishal wrote:
> I am new to sql and require some help on cursors?
> what are they and how and why are they used for???
>
>
> it will be kind enough if anyone helps me in this regards..
>
>
> regards
> vishal jain.
Cursors are data structures that allow you to manipulate the results of
a query one row at a time. Typically we only do that in client
application code not in SQL. That's because it is usually much faster,
easier, more concise and more maintainable to use "set based" SQL code
- code that manipulates entire sets of data rather than one row at a
time.
If you are new to SQL then my advice is that you ignore cursors until
you get a lot more expert with set based SQL code. Although there are
certainly legitimate uses for them, cursors are too often badly misused
by the inexperienced who don't know any better. Only when you have lots
and lots of experience in "real" SQL will you have the sense to
recognise when a cursor is an appropriate solution.
That may not sound like a very helpful answer but if you consider that
probably at least 99% of what the average SQL developer does can be
done without a cursor you will realise that there are lots more
important things to learn first.
--
David Portas, SQL Server MVP
Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.
SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--
[Back to original message]
|