Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Cursor Vs Temp Table

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

In this post, I will showcase the steps for how to create groups in Office 365. Office 365 groups allow for ease of flexibility and collaboration between staff members.
Steps to fix error: “Couldn’t mount the database that you specified. Specified database: HU-DB; Error code: An Active Manager operation fail”
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…

885 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