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
 General SQL Server Forums
 New to SQL Server Programming
 Who to take advice from

Author  Topic 

WJHamel
Aged Yak Warrior

651 Posts

Posted - 2012-06-13 : 14:20:02
If i ask five different people's advice in my office, as you might imagine, i'll get five different solutions. One never even resembling the next. The lead DBA here, ALWAYS uses cursors to get from point A to point B in everything. The boss always avoids cursors and still gets the job done. The problem comes when the boss is gone and i'm stuck asking the lead DBA for advice. The word on the streets is that i should NOT develop the habit of using cursor based logic whenever i can avoid it. Just wondering how many of y'all support that idea, or should i just give up and start learning "her way" of doing things (which i hate)

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2012-06-13 : 15:05:48
Using cursors is okay if you have to loop. Whether or not you have to loop is dependent on the problem. Looping can be more efficient in certain circumstances. It all depends on what your testing shows when doing the comparisons.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-06-13 : 15:15:44
most of scenarios can be dealt with an efficient set based solution in t-sql. With that being said, there are some scenarios where set based solution can be difficult to implement and where cursors can come handy in such cases. It really depends on scenario and we need to determine what exactly scenario is asking before going for any one type of approach

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

Go to Top of Page

WJHamel
Aged Yak Warrior

651 Posts

Posted - 2012-06-13 : 15:16:07
Looping IS alot of where she depends on cursors. We do alot of that in our data conversions. therefore my perceptions are that i should get more comfortable with use of cursors in general. I was just getting my brain around really efficient use of CE's. Not looking forward to cramping my brain again.
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2012-06-13 : 15:21:52
ABSOLUTELY NEVER
NEVER
NEVER
NEVER
NEVER
NOT EVEN ONCE
use a cursor. Kill a million puppies and kittens instead, since that's morally equivalent with cursor use.

I like how your DBA wants you to do things "her way" and use cursors, and Tara replies that they're "okay". Something you're not telling us?
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2012-06-13 : 15:30:17
Lol!

And I don't use cursors. I use WHILE loops. They are the same though, essentially.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2012-06-13 : 15:46:45
For maintenance tasks, cursors are inevitable. Such as reindexing and compressing indexes and tables.
For data tasks, T-SQL is the more efficient way to solve a problem. And that's even more true with SQL Server 2012.

However, depending on how you have stored the data, a cursor may be faster than T-SQL.


N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

WJHamel
Aged Yak Warrior

651 Posts

Posted - 2012-06-14 : 08:32:12
i WISH tkizer worked in my office.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-06-14 : 08:38:12
quote:
Originally posted by WJHamel

i WISH tkizer worked in my office.


you don't say


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2012-06-14 : 08:40:49
Try boith methods and decide which you prefer.
Using a cursor may sometimes be slightly better but can be much worse - so you won't go far wrong if you never touch them.
For small sets of data it dodesn't really matter - just a good idea to get used to avoiding them.
An explicit cursor is never needed.

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

Sachin.Nand

2937 Posts

Posted - 2012-06-14 : 09:13:12
quote:
Originally posted by nigelrivett

.....

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.



I think Nigel's signature says it all..Period..

After Monday and Tuesday even the calendar says W T F ....
Go to Top of Page
   

- Advertisement -