Solved

Cursor Vs Temp Table

Posted on 2010-09-08
3
981 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
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article describes my battle tested process for setting up delegation. I use this process anywhere that I need to setup delegation. In the article I will show how it applies to Active Directory
There's a lot of hype surrounding blockchain technology. Here's how it works and some of the novel ways it' s now being used - including for data protection.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

856 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