Solved

Cursor Vs Temp Table

Posted on 2010-09-08
3
1,012 Views
Last Modified: 2012-05-10
Should one use cursors or temporary tables in Sybase?

For either one, if there could be an example of what could be used in certain scenarios, that would be helpful.

Thanks.
0
Comment
Question by:4Learning
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 14

Assisted Solution

by:Jan Franek
Jan Franek earned 250 total points
ID: 33634206
Cursors are generaly very slow compared to set based SQL commands. So, use them only if you can't do the job using "normal" SQL.

Temporary tables are different thing than cursors, so it's hard to answer your question.

What is the problem, that you want to solve ?
0
 
LVL 24

Accepted Solution

by:
Joe Woodhouse earned 250 total points
ID: 33652291
There are other options besides. :) If you are only going to use the rows in a temp table once, you may be better off creating a view and selecting from that - same number of reads but zero writes and zero transaction log records compared to a temp table.

I will go so far as to say there are almost no situations which warrant using a cursor. The only one I have ever been able to come up with is when you want to launch a different stored procedure at run time on a row-by-row basis. Anything that can be written in set-based SQL should be. :)

I think people misuse temp tables too though - I've seen plenty of code where rows are loaded into a temp table, used one, pushed into another, etc etc, for a chain of a dozen temp tables each used only once. Usually that can be rewritten into fewer steps.

So really my first question is are you certain you need either cursors or temp tables at all?
0
 

Author Closing Comment

by:4Learning
ID: 33851533
Question answered
0

Featured Post

Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Originally, this post was published on Monitis Blog, you can check it here . It goes without saying that technology has transformed society and the very nature of how we live, work, and communicate in ways that would’ve been incomprehensible 5 ye…
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question