SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Administration
 CURSOR error.
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

benildusmuerling
Yak Posting Veteran

Australia
81 Posts

Posted - 06/21/2012 :  23:32:57  Show Profile  Reply with Quote
Thanks for reading this post, can someone help me in helping what would be the cause of this error

'Msg 16915, Level 16, State 1, Line 513
A cursor with the name 'cur_distSummary' already exists.
Msg 16905, Level 16, State 1, Line 517
The cursor is already open.
Msg 16943, Level 16, State 4, Line 518
Could not complete cursor operation because the table schema changed after the cursor was declared.'

Thanks

AB

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 06/21/2012 :  23:37:19  Show Profile  Reply with Quote
its obvious. check if you've explicitly closed the cursor

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22769 Posts

Posted - 06/22/2012 :  08:40:10  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
Also what are youdoing with the cursor?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

benildusmuerling
Yak Posting Veteran

Australia
81 Posts

Posted - 06/24/2012 :  19:43:09  Show Profile  Reply with Quote
Hi All,

Can anyone tell me if I replace a cursor to another loop like (while exists select id from table), would this immensely improve performance.

Thanks,

AB
Go to Top of Page

xhostx
Constraint Violating Yak Guru

USA
277 Posts

Posted - 06/29/2012 :  09:32:24  Show Profile  Reply with Quote
quote:
Originally posted by benildusmuerling

Hi All,

Can anyone tell me if I replace a cursor to another loop like (while exists select id from table), would this immensely improve performance.

Thanks,

AB



Performance wise: Cursors are most likely to be avoided unless needed. Also, in SQL cursors has status to check if there's more data to pass to be treated inside the while loop.

Try to take out not needed statements to improve the performance, and look at your execution plans.
luck,

--------------------------
Get rich or die trying
--------------------------
Go to Top of Page

DKnight
Starting Member

1 Posts

Posted - 11/28/2012 :  13:25:51  Show Profile  Reply with Quote
Don't forget that in addition to closing the cursor you need to DEALLOCATE the cursor.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 12/02/2012 :  02:39:43  Show Profile  Reply with Quote
quote:
Originally posted by benildusmuerling

Hi All,

Can anyone tell me if I replace a cursor to another loop like (while exists select id from table), would this immensely improve performance.

Thanks,

AB


One thing to consider is why do you need to go for row by row processing and why cant you implement it in set based manner?
Set based solution would be in most cases the fastest solution to implement

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Howard43Willard
Starting Member

USA
8 Posts

Posted - 12/02/2012 :  20:21:46  Show Profile  Reply with Quote
Could not complete cursor operation because the table schema changed after the cursor was declared.






Edited by - Howard43Willard on 12/02/2012 20:27:01
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.17 seconds. Powered By: Snitz Forums 2000