Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Administration (2000)
 Seeking Knowledge about cursors

Author  Topic 

arorarahul.0688
Posting Yak Master

125 Posts

Posted - 2007-10-23 : 04:10:13
Hi All,
this is my first post on this site.
Whoever is looking in this post plz give me some idea about Cursors in Sqlserver how they works and from where should i start to get perfection in cursors in sqlserver


regards,
Rahul

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-10-23 : 04:14:11
just key in CURSOR in the Google Custom Search box on the upper right of this screen and hit Search


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-10-23 : 04:16:25
But a general advice is, try to perfect your Select Query before looking at cursor. 99% of the time you don't need cursor at all. 1st Priority is to learn Set-Based Query. Once you have perfect that, then take a peep at cursor.


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

jackv
Master Smack Fu Yak Hacker

2179 Posts

Posted - 2007-10-23 : 04:55:32
The main problem with cursors is that it is a row by row processing which creates a network roundtrip at every row. Whereas the set based approach will return the whole recordset

Jack Vamvas
--------------------
Search IT jobs from multiple sources- http://www.ITjobfeed.com
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-10-23 : 05:28:13
Even if you have a CURSOR inside a Stored Procedure and you only call then SP?
Where comes the roundtrip in then?



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-10-23 : 05:31:55
quote:
Originally posted by arorarahul.0688

Hi All,
this is my first post on this site.
Whoever is looking in this post plz give me some idea about Cursors in Sqlserver how they works and from where should i start to get perfection in cursors in sqlserver


regards,
Rahul


Which is your previous RDBMS?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

jackv
Master Smack Fu Yak Hacker

2179 Posts

Posted - 2007-10-23 : 11:48:23
Peso , in the instance of a CURSOR within a SP and you only then call SP , in that case you don't have a network roundtrip. I was trying to make the point of row by row processing , in a certain situation

Jack Vamvas
--------------------
Search IT jobs from multiple sources- http://www.ITjobfeed.com
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2007-10-23 : 12:43:17
You have a round trip to the database engine and it also cannot optimise the query for the final result.
Sometimes a cursor can be marginally faster but usually it's thousands (or millions or more) of times slower.


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-10-24 : 02:50:57
quote:
Originally posted by nr

You have a round trip to the database engine and it also cannot optimise the query for the final result.
Sometimes a cursor can be marginally faster but usually it's thousands (or millions or more) of times slower.


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.


By sometimes, did you mean "Genereating Running total using a cursor"?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -