Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12345»»»

There Must Be 15 Ways To Lose Your Cursors… Part 2: Just Put It in a S Expand / Collapse
Author
Message
Posted Saturday, April 25, 2009 12:18 PM


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Friday, March 28, 2014 2:25 PM
Points: 9,902, Visits: 9,479
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."
Post #704504
Posted Sunday, April 26, 2009 7:47 PM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Tuesday, April 01, 2014 5:55 PM
Points: 957, Visits: 1,027
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!
Post #704687
Posted Sunday, April 26, 2009 10:10 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 5:32 AM
Points: 22,507, Visits: 30,221
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.




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)
Post #704703
Posted Sunday, April 26, 2009 11:11 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Yesterday @ 4:00 PM
Points: 35,967, Visits: 30,258
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.


--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."

"Change is inevitable. Change for the better is not." -- 04 August 2013
(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #704720
Posted Monday, April 27, 2009 12:45 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Tuesday, March 25, 2014 12:35 AM
Points: 1,172, Visits: 727
Well done! Can you tell us the publishing date of Part 3?

The results of the comparison: no spoilers here

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

Rewrite:
CpuMs: 94
LogRds: 236
Elapsed: 89






Dutch Anti-RBAR League
Post #704737
Posted Monday, April 27, 2009 12:50 AM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Tuesday, April 15, 2014 10:46 AM
Points: 3,241, Visits: 4,987
Another great Article.

Thanks...


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

Sometimes, winning is not an issue but trying.

You can check my BLOG here

Post #704739
Posted Monday, April 27, 2009 1:03 AM


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Friday, March 28, 2014 2:25 PM
Points: 9,902, Visits: 9,479
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."
Post #704742
Posted Monday, April 27, 2009 1:51 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, December 02, 2009 6:54 AM
Points: 7, Visits: 31
The fact you even have to tell so called developers this stuff is frightening.
Post #704757
Posted Monday, April 27, 2009 2:29 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Tuesday, April 15, 2014 8:46 AM
Points: 335, Visits: 1,956
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


Post #704770
Posted Monday, April 27, 2009 2:36 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, December 02, 2009 6:54 AM
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?
Post #704774
« Prev Topic | Next Topic »

Add to briefcase 12345»»»

Permissions Expand / Collapse