Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


There Must Be 15 Ways To Lose Your Cursors… Part 2: Just Put It in a S


There Must Be 15 Ways To Lose Your Cursors… Part 2: Just Put It in a S

Author
Message
RBarryYoung
RBarryYoung
SSCrazy Eights
SSCrazy Eights (9.4K reputation)SSCrazy Eights (9.4K reputation)SSCrazy Eights (9.4K reputation)SSCrazy Eights (9.4K reputation)SSCrazy Eights (9.4K reputation)SSCrazy Eights (9.4K reputation)SSCrazy Eights (9.4K reputation)SSCrazy Eights (9.4K reputation)

Group: General Forum Members
Points: 9438 Visits: 9517
Comments posted to this topic are about the item There Must Be 15 Ways To Lose Your Cursors… Part 2: Just Put It in a S

-- RBarryYoung, (302)375-0451 blog: MovingSQL.com, Twitter: @RBarryYoung
Proactive Performance Solutions, Inc.
"Performance is our middle name."
Bruce W Cassidy
Bruce W Cassidy
Right there with Babe
Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)

Group: General Forum Members
Points: 787 Visits: 1033
Aha!

I have to say I enjoyed this more than the first article, largely because the first article was really just an introduction to the topic.

I like your use of examples where I can just see a developer writing that sort of code, usually because they don't know better.

I also like the introduction of a method for converting cursor statements into set-based equivalents. I think as you continue to walk through each of the parts of that method, it will make it easier for people new to thinking and working with sets to apply to their own code. Kudos for that.

For completeness, will you look at rewriting cursors into just using a loop (without the actual cursor, but otherwise identical)? Because that's another form of code that can also be replaced by set-based code.

I'm happy to give examples if you need them.

Well done!

Lynn Pettis
Lynn Pettis
SSC-Insane
SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)

Group: General Forum Members
Points: 24207 Visits: 37978
Very good article. In fact, I'm thinking of printing each of the articles in the series and providing them to my team as required reading.

The test harness you have created is also well done, and I think that as well can be incorporated in other test environments.

I'm eagerly awaiting to see what others think of this article.

Cool
Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Jeff Moden
Jeff Moden
SSC-Forever
SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)

Group: General Forum Members
Points: 45145 Visits: 39923
Nicely done, Barry... I really like the way the story is unfolding in this series... very easy reading, as well. I absolutely agree that you have real life examples because I've seen the same thing not only on these fine forums, but in real production code, as well.

The bad part about this article is... I've finally learned how to write a Cursor and may have to burn out my mind's-eye to rid myself of the images of RBAR on steriods. :-P

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
Although they tell us that they want it real bad, our primary goal is to ensure that we dont actually give it to them that way.
Although change is inevitable, change for the better is not.
Just because you can do something in PowerShell, doesnt mean you should. Wink

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
gserdijn
gserdijn
Ten Centuries
Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)

Group: General Forum Members
Points: 1341 Visits: 816
Well done! Can you tell us the publishing date of Part 3?

The results of the comparison: no spoilers here Cool

Original code:
CpuMs: 8750
LogRds: 834261
Elapsed: 9898

Rewrite:
CpuMs: 94
LogRds: 236
Elapsed: 89




Dutch Anti-RBAR League
Atif-ullah Sheikh
Atif-ullah Sheikh
Hall of Fame
Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)

Group: General Forum Members
Points: 3280 Visits: 5160
Another great Article.

Thanks...

----------------------------------------------------------------------------------------------------------------------------------------------------------------------

Sometimes, winning is not an issue but trying.

You can check my BLOG here


RBarryYoung
RBarryYoung
SSCrazy Eights
SSCrazy Eights (9.4K reputation)SSCrazy Eights (9.4K reputation)SSCrazy Eights (9.4K reputation)SSCrazy Eights (9.4K reputation)SSCrazy Eights (9.4K reputation)SSCrazy Eights (9.4K reputation)SSCrazy Eights (9.4K reputation)SSCrazy Eights (9.4K reputation)

Group: General Forum Members
Points: 9438 Visits: 9517
Thanks fro the support Folks! And Jeff, yeah, I had the same problem when writing these article.

As for part 3, unfortunately medical issues have kept me from completeing it, but I will let you know as soon as I do. In fact these same medical issues are going to keep me off-line most of today, however many of the heavy poster has offered to step-in to fkk the gaps and answer any thecnical questions

thanks again! ...

-- RBarryYoung, (302)375-0451 blog: MovingSQL.com, Twitter: @RBarryYoung
Proactive Performance Solutions, Inc.
"Performance is our middle name."
jwheeler-985942
jwheeler-985942
Forum Newbie
Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)

Group: General Forum Members
Points: 7 Visits: 31
The fact you even have to tell so called developers this stuff is frightening.
Samuel Vella
Samuel Vella
Old Hand
Old Hand (393 reputation)Old Hand (393 reputation)Old Hand (393 reputation)Old Hand (393 reputation)Old Hand (393 reputation)Old Hand (393 reputation)Old Hand (393 reputation)Old Hand (393 reputation)

Group: General Forum Members
Points: 393 Visits: 2141
jwheeler (4/27/2009)
The fact you even have to tell so called developers this stuff is frightening.


Not really and it's something I've seen a few times...

When someone has a background in VB or C and has been dumped into SQL development then they might be able to write code but they lack the set based thinking which a good DB developer needs (they might not even be aware of being able to return sets depending on how much exposure they're had to databases in their previous life).

Usually a helping hand with their first few pieces of work will get them thinking the right way from the outset.

I know from experience when dabbling in ASP .NET that something which I've spent hours and several tens of lines of code trying to get to work can be ripped apart and rewritten as a very simple class by someone who knows what they're doing
jwheeler-985942
jwheeler-985942
Forum Newbie
Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)

Group: General Forum Members
Points: 7 Visits: 31
Samuel Vella (4/27/2009)
jwheeler (4/27/2009)
The fact you even have to tell so called developers this stuff is frightening.


Not really and it's something I've seen a few times...

When someone has a background in VB or C and has been dumped into SQL development then they might be able to write code but they lack the set based thinking which a good DB developer needs (they might not even be aware of being able to return sets depending on how much exposure they're had to databases in their previous life).

Usually a helping hand with their first few pieces of work will get them thinking the right way from the outset.

I know from experience when dabbling in ASP .NET that something which I've spent hours and several tens of lines of code trying to get to work can be ripped apart and rewritten as a very simple class by someone who knows what they're doing



Then surely the manager hasn't done their job by employing the wrong tool for the task?

If you have database development to be done you either employ a db dev or a C# / VB developer who is also a SQL dev. You don't buy a hammer to put a screw in the wall, surely?
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search