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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Site Related Forums
 Article Discussion
 Are Curosors Avoidable always?
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Nazim
A custom title

United Arab Emirates
1408 Posts

Posted - 10/21/2001 :  11:26:55  Show Profile  Reply with Quote
i was just going thru Robin Dewson interview. he mentioned in the course of interview that at times avoiding cursors is not possible. if i look at sqlteam answers and esp the posts from nr,should appreciate it he has been successful in answering every Question avoiding cursors (otherwise normal minds like me would have used them:)).

i would love to see some problems where Robin Dewson words become true, and what are the reasons for it.



Computers dont do what u want to them to do, they do what you instruct them to do

robvolk
Most Valuable Yak

USA
15732 Posts

Posted - 10/21/2001 :  13:48:21  Show Profile  Visit robvolk's Homepage  Reply with Quote
Your time is far better spent looking for non-cursor solutions to a problem than looking for a problem that works better with a cursor. (if cursors solve a problem you don't have, they're useless; if you have a problem that has a set-based solution, cursors are...USELESS!)

If you have a specific problem that you haven't been able to solve using SQL, before you reach for a cursor, post it here and let's have a crack at it.

About the only example I've found on SQL Team where a cursor turned out to be better than set-based solutions was here:

http://www.sqlteam.com/item.asp?ItemID=3856

And when you read it, no one was more surprised than Garth. He also stated that he still advises people to avoid them.

BTW, re-read Robin's interview again, you'll find he gives the EXACT SAME advice, more than once: AVOID USING CURSORS AS MUCH AS POSSIBLE. (even in the paragraph you mentioned!)

I strongly recommend you pick up a book by Joe Celko or Ken Henderson's The Guru's Guide to Transact-SQL. You'll find plenty of examples of difficult SQL problems solved without using cursors. It will give you a lot more respect (the proper respect) for what set-based SQL can do, and you'll stop worrying about when to use a cursor or not.

(I humbly suggest this link as a possible example: http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=9978&CAT_ID=3&FORUM_ID=5&Forum_Title=Developer&Topic_Title=Cursor+or+Not )

My 2ยข

Edited by - robvolk on 10/21/2001 14:52:14
Go to Top of Page

nr
SQLTeam MVY

United Kingdom
12543 Posts

Posted - 10/21/2001 :  17:02:11  Show Profile  Visit nr's Homepage  Reply with Quote
Cursors are never necessary as you can always duplicate the processing by using a temp table.
It may not be more efficient but it is always possible.



==========================================
Cursors are useful if you don't know sql.
Beer is not cold and it isn't fizzy.
Go to Top of Page

Nazim
A custom title

United Arab Emirates
1408 Posts

Posted - 10/24/2001 :  08:43:47  Show Profile  Reply with Quote
Thanx Rob, i would definetly go thru ken's book.
but if any1 of u guru's can come up with a article xplaining the ways and means to avoid Cursors it will b great help to pple like me.

i do have a problem it involves vb too, should i post it.

-------------------------
Solitude is a good place to visit, but a horrible place to livein
Go to Top of Page

AjarnMark
SQL Slashing Gunting Master

USA
3246 Posts

Posted - 10/24/2001 :  12:12:49  Show Profile  Visit AjarnMark's Homepage  Reply with Quote
Here are a couple of SQLTeam articles that talk about typical scenarios when a cursor would be used, and ways around it...
http://www.sqlteam.com/item.asp?ItemID=2368
http://www.sqlteam.com/item.asp?ItemID=2652
http://www.sqlteam.com/item.asp?ItemID=5761


-------------------------------------------------------------------
Just because you CAN do something does not mean that you SHOULD!
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.04 seconds. Powered By: Snitz Forums 2000