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 |
|
chedderslam
Posting Yak Master
223 Posts |
Posted - 2009-08-26 : 14:31:27
|
| I'm trying to rewrite a cursor as a select but haven't had much luck. I'm trying to make it faster, so which is faster? |
|
|
safderalimd
Starting Member
32 Posts |
Posted - 2009-08-26 : 15:37:59
|
| My answer doesnt address your question, but here is my opinion on cursors and performance.99 times out of 100, you can avoid cursors. To me cursor is lazy programmers tool. Did you try using set based SQL operation? If you cant then why not use temp tables in combination with set based SQL.I do not want to underestimate your skills, maybe your requirement falls in 1 out of 100 where you need cursor bcaz of poor database design. |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2009-08-26 : 15:38:18
|
quote: FAST_FORWARD implies READ_ONLY (although I often include READ_ONLY anywayfor documentation). Personally I always specify LOCAL unless a globalcursor is needed. AFAIK, the fastest server cursor is:DECLARE MyCursor LOCAL FAST_FORWARD FORSELECT ...
N 56°04'39.26"E 12°55'05.63" |
 |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2009-08-26 : 15:50:08
|
>>To me cursor is lazy programmers toolI think when a developer uses a cursor when a set based option is readily available is not because they are being lazy but rather they are still in the mind-set of a procedural language where set-based operations are simply not available. Besides, an UPDATE or INSERT statement is much simpler to type then to do the same thing with a cursor. Be One with the OptimizerTG |
 |
|
|
|
|
|