SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Who to take advice from
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

WJHamel
Aged Yak Warrior

USA
614 Posts

Posted - 06/13/2012 :  14:20:02  Show Profile  Reply with Quote
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

USA
35007 Posts

Posted - 06/13/2012 :  15:05:48  Show Profile  Visit tkizer's Homepage  Reply with Quote
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

India
47040 Posts

Posted - 06/13/2012 :  15:15:44  Show Profile  Reply with Quote
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

USA
614 Posts

Posted - 06/13/2012 :  15:16:07  Show Profile  Reply with Quote
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

USA
15557 Posts

Posted - 06/13/2012 :  15:21:52  Show Profile  Visit robvolk's Homepage  Reply with Quote
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

USA
35007 Posts

Posted - 06/13/2012 :  15:30:17  Show Profile  Visit tkizer's Homepage  Reply with Quote
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

Sweden
29138 Posts

Posted - 06/13/2012 :  15:46:45  Show Profile  Visit SwePeso's Homepage  Reply with Quote
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

USA
614 Posts

Posted - 06/14/2012 :  08:32:12  Show Profile  Reply with Quote
i WISH tkizer worked in my office.
Go to Top of Page

webfred
Flowing Fount of Yak Knowledge

Germany
8513 Posts

Posted - 06/14/2012 :  08:38:12  Show Profile  Visit webfred's Homepage  Reply with Quote
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
Flowing Fount of Yak Knowledge

United Kingdom
3328 Posts

Posted - 06/14/2012 :  08:40:49  Show Profile  Visit nigelrivett's Homepage  Reply with Quote
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
Flowing Fount of Yak Knowledge

2937 Posts

Posted - 06/14/2012 :  09:13:12  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000