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.
| Author |
Topic |
|
Non-conformer
Starting Member
14 Posts |
Posted - 2005-06-30 : 11:44:52
|
| Hello all,I have a forward-only cursor that I need to "re-wind" back to the 1st record. Which is better: a) declare it as a "scroll" cursor and "fetch first", or b) close it and re-open it? |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2005-06-30 : 11:47:33
|
c) don't use cursors at all.is the correct answerGo with the flow & have fun! Else fight the flow |
 |
|
|
Thrasymachus
Constraint Violating Yak Guru
483 Posts |
Posted - 2005-06-30 : 11:58:10
|
| go to google and type in SQL Server set based query or post it here and someone might rewrite it for you.Sean RoussyPlease backup all of your databases including master, msdb and model on a regular basis. I am tired of telling people they are screwed. The job you save may be your own.I am available for consulting work. Just email me though the forum. |
 |
|
|
Non-conformer
Starting Member
14 Posts |
Posted - 2005-06-30 : 12:11:13
|
| Well, I am aware of the drawbacks of using cursors. However, they are a tool, and like any tool, one should use the right tool for the right job. (ex: If I need to drive a philips head screw, do I use a philips screwdriver, or a chain saw?) Cursors are a good choice when the developer needs to take 1 row of data and process the bejeezus out of it before moving onto the next row. Can it be down withOUT a cursor? Sure, but from a program maintainability point-of-view, there comes a time and place where procedural code is just a heck of a lot easier to read and understand.Of course this is all just my humble opinion.N.C. |
 |
|
|
Thrasymachus
Constraint Violating Yak Guru
483 Posts |
Posted - 2005-06-30 : 12:22:40
|
| every rule does have it's exception but for 1000 times a developer uses a cursor there is maybe 1 time it is truly needed. like I said already today on another thread I am not haveingthis debate...http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=51750So go ahead and bog down your server and cause some deadlocking and blocking etc...The only time I can see a cursor being useful is when the processing of a record inside the cursor depends on the values already processed by the same cursor.Sean RoussyPlease backup all of your databases including master, msdb and model on a regular basis. I am tired of telling people they are screwed. The job you save may be your own.I am available for consulting work. Just email me though the forum. |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2005-06-30 : 12:33:14
|
i'd go with a) if you really must.Go with the flow & have fun! Else fight the flow |
 |
|
|
|
|
|
|
|