Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Cursor Vs Temp Table

Posted on 2010-09-08
3
Medium Priority
?
1,027 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 1000 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 1000 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

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

Question has a verified solution.

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

We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
If you are a mobile app developer and especially develop hybrid mobile apps then these 4 mistakes you must avoid for hybrid app development to be the more genuine app developer.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

715 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