Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Site Related Forums
 The Yak Corral
 Cursor Hell

Author  Topic 

derrickleggett
Pointy Haired Yak DBA

4184 Posts

Posted - 2004-03-12 : 08:56:55
Is it just me or we getting way more people using cursors lately?

--Can I find a good excuse to use a cursor?
--I know you can only do this with a cursor, but.... (???)
--Is this cursor right? (umm, that would be NO!!!!!)
--My cursor inside of a cursor inside of a cursors' cursor is running slow, can you help me. (We could stick you in a cursor.)

Is precious a cursor? Do you love your precious? Your cursor must return to the fire of your smoking, melted server. Only then will the world be made whole.



MeanOldDBA
derrickleggett@hotmail.com

When life gives you a lemon, fire the DBA.

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2004-03-12 : 09:00:56
I don't think the numbers are significantly above average, we've been getting stupid questions for years


Damian
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2004-03-12 : 09:07:11
Used to be a lot of people using them - died down a bit - now is growing again.
It's due to the sort of people using sql server.
When application programmers try to code in sql they find cursors and can use them to emulate application code - then they find that it runs like a dog and discover the wonders of set based programming (after complaining about sql server being too slow and that they coud do this in C or Oracle).
Next are a lot of posts about how to code things which (after a lot of comments) get down to innappropriate data structures and a schema redesign.
You then get a productive database developer and valuable member of the site.
Takes about 2 years.

Just had a leaving drink (proper beer ish - continuing later).
Anyone dare to offer me a job?


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2004-03-12 : 09:14:17
Where are you based at the moment Nigel ? Still in the US or back home ?


Damian
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2004-03-12 : 09:16:50
In the UK for the moment - may be back in the USA shortly for a few months.
Definitely in OZ for at least a few weeks within the next 6 months. Planned arrival just after Easter but project plan subject to outside influence.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2004-03-12 : 09:18:08
Cursors are very easy to understand and they give a method of accomplishing advanced tasks in a comprehensible way for users that are not 100% fluent in the structured query language. Even though cursors are blowing performance alot of people out there are just thrilled to actually get something to work, and people like me that work in small businesses where I am the *only* IT-person don't have the time to go to all the courses and learn all the fancy stuff you DBA's or full-time developers do.

"All" you DBA's and MVP's do is to work on this while someone like me has to know iis, asp, asp.net, javascript, secure programming, dhcp/active directory, firewall-issues, windows/office/excel-troubleshooting and about a million other things (even take out the friggin trash and make coffee!) and I really need to know ALL these things by heart to do my job properly. Learning and understanding the nature of derived tables and all that stuff takes quite a bit of time and cursors are a quick and dirty way to do what you need to do without spending "an eternity" in development. Besides, allthough cursors blow performance I would say that not all have "a million" users to their database on a daily basis so to blow performance when you have 90% free capacity isn't THAT big of a deal...

I guess this is just in my own defence but I think you pro's should cut us rookies a little more slack than answering a question "Do I really need cursors?" with a "No!" without any further explanation like one of the MVP's just did here a few days ago.

--
Lumbago
"Real programmers don't document, if it was hard to write it should be hard to understand"
Go to Top of Page

drymchaser
Aged Yak Warrior

552 Posts

Posted - 2004-03-12 : 09:23:42
Uh oh!
Go to Top of Page

Amethystium
Aged Yak Warrior

701 Posts

Posted - 2004-03-12 : 09:29:46
Come on guys.... you are talking about n00bs. Switching between set based and recursive programming is not an easy task and takes a long time to master. Development tools (such as VB) do not do SQL Server any justice in my opinion. I’m sure you know what I mean, but having worked with VB for so long, it's hard to get back in to imaginative set based coding. And I think the keywords here are imagination and I'll throw in concepts too.

Set based programming requires imagination…. (smoking pot on a daily basis massively improves your imagination). Oh yea.. you should see the $hit that I’ve been coming up with lately. Hint : Lack of silly questions from me on the forums lately

Recursive programming and specifically development tools such as VB encourage you in a way to forget fundamental concepts which every programmer should have. Perhaps the member joining this board are use to using such development tools?

Anyway, now that I have been using SQL Server for 2-3 years I can honestly say that I have become a much better developer as a whole because my problem solving approach (thanks to you guys as well) has improved big time thanks in part to my set based programming.

It’s amazing what you can do with a table and a few keywords isn’t it!

________________
Make love not war!
Go to Top of Page

ditch
Master Smack Fu Yak Hacker

1466 Posts

Posted - 2004-03-12 : 09:31:16
quote:
Originally posted by Lumbago

(even take out the friggin trash and make coffee!)


Haven't you written some fancy app, burnt it on to a microchip and installed it in the coffee machine to automate this process yet?



Duane.
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2004-03-12 : 09:37:55
Very old people (friends have told me about this) will remember about vinyl records.
There was a theory that the speakers were the thing that you should spend all your money on.
When technology improved it became apparent that however much you spend on processing the signal you can't correct a poor source so spend as much as you can on the record deck (and decent recordings) and get reasonable amps and speakers.

Building systems is a bit like that - the database is the source and if the data structures are inappropriate or the data incorrect you will always be fighting a losing battle.
Doesn't matter how strong the applcation skills are - as soon as you get a reasonable quantity of data the weaknesses in the system will be apparent if it's not built on a sound foundation. First make sure the structure is right (or at least reasonable) then the data access methods then look at the presentation. And keep the layers separate.
That's why a lot of systems seem to work initially and test OK with small amounts of data but fall over later when the usage grows.

And it's why I try never to control detailed development of all parts of the system. It's difficult to keep the layers separate when you are involved in all of them.
Have at least two people - a database expert who also knows the data access part of the middle layer and the presentation layer a bit and a presentation layer expert who also know the data acces part of the middle layer. And if they don't argue something is probably wrong.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

JimL
SQL Slinging Yak Ranger

1537 Posts

Posted - 2004-03-12 : 09:37:56
quote:
people like me that work in small businesses where I am the *only* IT-person don't have the time to go to all the courses and learn all the fancy stuff you DBA's or full-time developers do.





Sorry Lumbago

Wrong answer.

Not only am I the only I.T. but when I went to school there was nothing but Cursor type programing (We called them Loops)Got out for 15 years and had to start all over 2 years ago (I have never had a SQL class other than this site).

I took one look at SQL and went wow we can do it without loops!!!!!

I am not trying to be insulting but trust me, Learn to do it right an you will never go back to Cursors as a standard.






Jim
Users <> Logic
Go to Top of Page

JimL
SQL Slinging Yak Ranger

1537 Posts

Posted - 2004-03-12 : 09:44:32
quote:
Originally posted by nr
Very old people (friends have told me about this) will remember about vinyl records.



Should I take that Personally Nigel. LOL



Jim
Users <> Logic
Go to Top of Page

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2004-03-12 : 09:48:49
Lumbago, ummm, how do I say this nicely....

Bullshit!

Hmm, that wasn't nice.... but you get the point


quote:
Originally posted by Lumbago

Cursors are very easy to understand and they give a method of accomplishing advanced tasks in a comprehensible way for users that are not 100% fluent in the structured query language.


That's simply not true.
Take a look at some of the godawful messy cursor code that has been presented here in the last few weeks. It's not comprehensible, and most of it just plain doesn't work right.

Most of it has been re-written to REALLY simple set based statements that could be written with a tiny bit of effort (is 10 minutes too much to ask) put into reading the freakin manual.


quote:

Even though cursors are blowing performance alot of people out there are just thrilled to actually get something to work


Personally I'm happier to have a job done well, it's called being a professional.


quote:

and people like me that work in small businesses where I am the *only* IT-person


I am a freelance developer, my current client has less than 10 employees.


quote:

don't have the time to go to all the courses and learn all the fancy stuff you DBA's or full-time developers do.


Make time. There would be a user group or two in your area, as a professional it's your responsibility to know your job and maintain your skills.

Read this http://software.ericsink.com/Career_Calculus.html


quote:

"All" you DBA's and MVP's do is to work on this while someone like me has to know iis, asp, asp.net, javascript, secure programming, dhcp/active directory, firewall-issues, windows/office/excel-troubleshooting and about a million other things


I'm not an MVP or a full time DBA. I have to do all of those things.


quote:

even take out the friggin trash and make coffee!


I'm working at home, nobody to do this stuff for me.



quote:

Learning and understanding the nature of derived tables and all that stuff takes quite a bit of time


That's why it's called a profession. Would you like your doctor to say "all that fancy surgery and medicine takes too long to learn, I'll just use leeches."



quote:

and cursors are a quick and dirty way to do what you need to do without spending "an eternity" in development. Besides, allthough cursors blow performance I would say that not all have "a million" users to their database on a daily basis so to blow performance when you have 90% free capacity isn't THAT big of a deal...


I think it's generally acknowledged that doing things right the first time will ALWAYS save you time in the long run. I also find it much quicker to write decent code than mess around with cursors. 90% of SQL you will write isn't that hard, unless you make it hard by having a cursor as the first tool in your toolbox.



quote:

I think you pro's should cut us rookies a little more slack than answering a question "Do I really need cursors?" with a "No!" without any further explanation like one of the MVP's just did here a few days ago.


It's the truth though. If you never get into the habit of using cursors as your first solution, you will never have to strugle to break away from them. Every time we convince someone not to use a cursor for something they don't need to, we are doing the developer community a huge service.


I think you are making excuses.
You are on track now, stick around here, read threads, answer where you can and you will learn a LOT in not a great deal of time.



Damian
Go to Top of Page

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2004-03-12 : 09:49:15
People; I'm not questioning if cursors are good or bad, I know for sure that they should be avoided (and I couldn't agree more to Nigels post). However this is not a question of right and wrong, rather a question working and not working. I was totally stoked a few years back when I first learned about stored procedures and found out that there is something other than inline sql and with 2 years in sql-development among other things I'm learning that there are more efficient ways of doing things than the stuff I did after 2 months. What I'm only asking is that you don't bust my balls for not beeing a pro right away...I'm getting there but it takes time.
Go to Top of Page

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2004-03-12 : 09:52:25
quote:

smoking pot on a daily basis massively improves your imagination



That's what YOU think.



Damian
Go to Top of Page

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2004-03-12 : 09:57:13
Merkin: you totally piss me off with this cocky attitude of yours. I'm not even gonna respond to all the bs of yours except for this: if you were to perform a bypass surgery on a patient, would this poor guy survive if you only had a 1 year medical education??
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2004-03-12 : 09:58:53
>> cut us rookies a little more slack than answering a question "Do I really need cursors?" with a "No!" without any further explanation like one of the MVP's just did here a few days ago.

That would probably be me.
Well look at the question. It is closed and the response is perfectly valid.
As a general rule of thumb it's a valuable conditioned reflex to learn.

A better question would be
"How should I do this without cursors"
or
"How should I do this"
or
"How could this be improved"

and then I could respond "get rid of the cursor" :).

OK I appologise - but I didn't have a lot of time and was going to post more but got sidetracked.


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2004-03-12 : 10:02:02
quote:
Originally posted by Lumbago

Merkin: you totally piss me off with this cocky attitude of yours.



OK, not the first time someone has said that to me. I would like to know what you disagree with though and why ?

I honestly don't think your situation is that different to most people here. It comes down to what you do about it.

quote:

if you were to perform a bypass surgery on a patient, would this poor guy survive if you only had a 1 year medical education??



I'm not sure what you are getting at here. If I didn't have the proper knowledge, then no he probably wouldn't. But that doesn't mean I'm going to do something half arsed and blame it on having to make the coffee.




Damian
Go to Top of Page

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2004-03-12 : 10:07:25
>> That would probably be me.

It probably was. But don't get me wrong; I have great respect for the work you and all the other people here do and the tremendous amount of help me and a bunch of others are getting here, I could not have done my job without it. So please don't be all offended with me bringing it up, that was not my intention at all, and I seriously hope I'm not facing a boicott (how do you spell that again??) for saying this. I was just trying to make the point that it's very easy for professionals that know all this by heart to make the rookie feel unwelcome. And I'm quite sure that this was not your intention... if all you guys just spare the "you-would-have-to-be-nuts-to-use-a-cursor"-talk and rather advice to do something else it would be great.
Go to Top of Page

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2004-03-12 : 10:22:02
I can't comment on all the things you were saying merkin cause it takes alot of time and I got alot of eyes in my back now wonering what the hell I'm doing in the middle of work-hours. But remarks like this just totally gets me:

>> Personally I'm happier to have a job done well, it's called being a professional.

By saying this you also say that:
1. I'm not a professional
2. "All" the work rookies do is crap
3. "If it works I can't use it because it still isn't good enaugh"
4. You never put anything into production that isn't 100% perfect
...and a few other things about your personal attitude towards people that just can't "make time" as you so boldly puts it.

I wouldn't actually like to take all this so much further because I really wanna stay friends with everybody here (I NEED YOU!! hehe), all I want is for you guys to appreciate the fact that we are all struggeling to get better, we just can't be perfect at everything from day one.
Go to Top of Page

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2004-03-12 : 10:23:52
Whee, .1k posts
Go to Top of Page
    Next Page

- Advertisement -