Solved

Cursor or subquery?

Posted on 2006-11-10
2
1,901 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

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

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
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.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

726 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