January 26, 2014 at 11:28 pm
Dear Friends,
we all know when use cursor the performance become slow,so my question is why cursor is slow?
Also want to find actual difference between While and Cursor..
Thanks is advance.
January 27, 2014 at 12:09 am
shubham.saxena67 (1/26/2014)
Dear Friends,we all know when use cursor the performance become slow,so my question is why cursor is slow?
Also want to find actual difference between While and Cursor..
Thanks is advance.
A cursor is slow because it does operations row by row, insteaf of doing things in a set-based manner (treating all rows at the same time).
Essentially a WHILE loop does the same (looping until a condition is met), but a cursor has additional constructs to go forward and backward in the set you're looping over (amongst other things).
It is essential to remember though that a WHILE loop is not better for performance.
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
January 27, 2014 at 12:15 am
Koen Verbeeck (1/27/2014)
but a cursor has additional constructs to go forward and backward in the set you're looping over (amongst other things).
Depending on the type of the cursor. A 'firehose' cursor can be slightly faster than the equivalent while loop.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply