Solved

Cursor or subquery?

Posted on 2006-11-10
2
1,821 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to shrink a transaction log file down to a reasonable size.

895 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

12 Experts available now in Live!

Get 1:1 Help Now