April 19, 2009 at 3:58 am
As you know, using cursor in stored procedure, etc. links to performance problem. Is there any article describing all situation in which something else can be used instead of cursors?
April 19, 2009 at 6:52 am
I highly recommend an article by Jeff Moden
http://www.sqlservercentral.com/articles/TSQL/62867/
If you really want to get into the depths of replacing a cursor follow this forum here on SSC
http://www.sqlservercentral.com/Forums/Topic695508-338-1.aspx
April 19, 2009 at 7:36 am
The answer is..."it depends!"
Sometimes, a cursor *is* the optimal solution. Not often, but it does happen.
If you tell us a little more background to your question, you may get a better answer!
P.S. It helps if you can show what your thoughts are, and why.
Cheers
Paul
April 19, 2009 at 9:45 am
Paul White
The answer is..."it depends!"
Sometimes, a cursor *is* the optimal solution. Not often, but it does happen.
Paul care to post some code that shows an example of where a cursor solution is better than a set based solution?
April 19, 2009 at 10:29 am
April 19, 2009 at 12:35 pm
Here[/url]'s the first article in an on-going series on that very subject (by me). The discussion attached to it gets pretty deeply into it also.
[font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
Proactive Performance Solutions, Inc. [/font][font="Verdana"] "Performance is our middle name."[/font]
April 19, 2009 at 2:59 pm
Thank you RBarryYoung.
@Bitbucket: Please note that Paul Neilsen and I are different people. There is a clue in my surname.
The example that springs to mind is where a stored procedure needs to be called to process an input set row-by-row. A good many real-world applications have this requirement somewhere. In principle, one might be able to replace the legacy code and cursor with a fully set-based solution, but (a) I don't think that's provably true; and (b) life is way too short.
Cheers,
Paul
April 19, 2009 at 5:32 pm
I have to admit, I found that very confusing.
[font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
Proactive Performance Solutions, Inc. [/font][font="Verdana"] "Performance is our middle name."[/font]
April 19, 2009 at 6:20 pm
It's gone now.
I didn't even try to understand it.
April 20, 2009 at 5:46 am
bitbucket (4/19/2009)
Paul White
The answer is..."it depends!"
Sometimes, a cursor *is* the optimal solution. Not often, but it does happen.
Paul care to post some code that shows an example of where a cursor solution is better than a set based solution?
Any situation where a set-based solution CANNOT be used. One example is where you need to call multiple sets of sprocs with inputs from a single row and those sprocs cannot be disassembled to combine into some potential set-based solution.
Best,
Kevin G. Boles
SQL Server Consultant
SQL MVP 2007-2012
TheSQLGuru on googles mail service
April 20, 2009 at 6:00 am
TheSQLGuru (4/20/2009)
Any situation where a set-based solution CANNOT be used. One example is where you need to call multiple sets of sprocs with inputs from a single row and those sprocs cannot be disassembled to combine into some potential set-based solution.
Me - some posts earlier!
The example that springs to mind is where a stored procedure needs to be called to process an input set row-by-row. A good many real-world applications have this requirement somewhere. In principle, one might be able to replace the legacy code and cursor with a fully set-based solution, but (a) I don't think that's provably true; and (b) life is way too short.
Spooky!
:laugh:
April 20, 2009 at 10:16 am
Great minds think alike! 😎
Best,
Kevin G. Boles
SQL Server Consultant
SQL MVP 2007-2012
TheSQLGuru on googles mail service
April 20, 2009 at 3:24 pm
TheSQLGuru (4/20/2009)
Great minds think alike! 😎
Speak for yourself! I pride myself on having a rather average mind :laugh:
April 20, 2009 at 11:18 pm
:laugh: :laugh: :laugh:
thanks all for your comments!
actually,I'm DBA ( a novice one 😛 ) and we usually have performance problem in our servers> I've decided to send all developer, general comments about when to use cursor and when replace cursor with something else. by the way, I'll read those articles carefully
Viewing 14 posts - 1 through 13 (of 13 total)
You must be logged in to reply to this topic. Login to reply