Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
1.44/5 (2 votes)
Is there any scenario exists where using cursor is the only solution and we can't replace it with any other options like "While loop", temp table etc.?
Posted
Updated 14-Nov-10 19:08pm
v2
Comments
Rajesh Anuhya 15-Nov-10 1:05am    
can you elaborate your Question???
Vivek Johari 15-Nov-10 1:11am    
Rajesh,
Through this question, I just want to know in which situations using cursor is the only solution since many database guys say that we should never use cursor and it is always possible to replace cursor with while loops or temp table etc.

The answer is Dynamic cursor. If we use Table variable or Temp table then it will contains the last committed data at the time of insertion into table variable or temp table. So you will not get the modified records or newly inserted records happened in base table.
While dynamic cursor gives you an option if there is any updates or insertion into base table then the changes will get reflected.
 
Share this answer
 
Comments
Vivek Johari 10-Dec-10 9:57am    
Hi Tarun thanks for the answer. Can you please give me an example which can help in better understanding........
I don't think so. We can use Table Variable or Temp Table instead of cursor and do the exactly same things with them.
 
Share this answer
 
If a DBA limits the size of queries / stored procedures
 
Share this answer
 
Comments
Vivek Johari 14-Dec-10 4:45am    
thanks for your answer. But if we use while loop instead of cursor it will not going to increase the size of quires/stored procedure much.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900