Solved

Cursor or subquery?

Posted on 2006-11-10
2
1,807 Views
Last Modified: 2008-02-20
Which one would be more efficient using a cursor in the stored proc to filter out un-wanted data or to use a dynamic subquery with the IN clause while updating?

Thanks!

0
Comment
Question by:srafi78
2 Comments
 
LVL 29

Assisted Solution

by:Nightman
Nightman earned 20 total points
ID: 17918365
A subquery - set based operations are almost always faster that multiple updates (and for really large sets, do it in batches).
0
 
LVL 3

Accepted Solution

by:
Birdbuster earned 30 total points
ID: 17919016
If I was you I would definetly not use a cursor and I would also try to avoid using a subquery, instead i would try to perform an INNER JOIN, but if that won't work for you case then I would use the Subquery.
You should try to avoid using a Cursor in Microsoft SQL Sever, because its very poor performance when compared to a cursor in Oracle.
Microsoft SQL Server works the best with Set Based querys and not cursors.

Hope this helps.

Thanks ...
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

760 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

20 Experts available now in Live!

Get 1:1 Help Now