Solved

Cursor Vs Temp Table

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this article, I will show you HOW TO: Perform a Physical to Virtual (P2V) Conversion the easy way from a computer backup (image).
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

758 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now