Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQLServerCentral.com
»
Editorials
»
GOTO and T-SQL
21 posts, Page 1 of 3
1
2
3
»
»»
GOTO and T-SQL
Rate Topic
Display Mode
Topic Options
Author
Message
Phil Factor
Phil Factor
Posted Wednesday, December 21, 2011 10:30 PM
Mr or Mrs. 500
Group: General Forum Members
Last Login: Today @ 4:00 AM
Points: 533,
Visits: 2,285
Comments posted to this topic are about the item
GOTO and T-SQL
Best wishes,
Phil Factor
Simple Talk
Post #1225546
Jeff Moden
Jeff Moden
Posted Wednesday, December 21, 2011 11:31 PM
SSC-Dedicated
Group: General Forum Members
Last Login: Today @ 10:37 AM
Points: 32,893,
Visits: 26,769
Well said, Phil. Perhaps this very well written editorial could be followed by a deeper article on why people shouldn't jump the gun because they read a title or an article by a famous author. Like Sergiy taught me, "A Developer must NOT GUESS! A Developer must know." The only way to know is to do some additional research and conduct your own tests with an open mind.
I've run into similar problems. For example, I've been told by a couple of friend DBAs in the past that we don't have to concern ourselves with properly sizing a database, that SQL Server was built to automatically handle all of that right from the startup of a new server. The information came from a sentence in the front of a book written by a very well known and respected author. People just don't understand that even "experts" like well known authors can make a "mistrake".
--Jeff Moden
"
RBAR
is pronounced "ree-bar" and is a "Modenism" for "
R
ow-
B
y-
A
gonizing-
R
ow".
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."
For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Post #1225569
Riken Patel
Riken Patel
Posted Thursday, December 22, 2011 2:20 AM
SSC-Enthusiastic
Group: General Forum Members
Last Login: 2 days ago @ 7:43 AM
Points: 157,
Visits: 195
Well said. When I read the first part of your paragraph I was shocked to see that I am being told not to use GOTO.
I had a similar reaction when reading an article about not using DBCC SHRINKFILE, at the start it was NO NO NO. But reading the whole article tells you that is not the case. I'm sure many people must read the first bit and leave it at that.
Post #1225620
IceDread
IceDread
Posted Thursday, December 22, 2011 2:33 AM
SSC Veteran
Group: General Forum Members
Last Login: Friday, November 16, 2012 3:47 AM
Points: 290,
Visits: 988
I have never felt the need to write a goto statement.
Post #1225623
ChiragNS
ChiragNS
Posted Thursday, December 22, 2011 2:36 AM
SSCrazy
Group: General Forum Members
Last Login: Wednesday, April 24, 2013 5:02 AM
Points: 2,365,
Visits: 1,825
I like this sentence in the article.
It is a shame that useful, but subtle, guidance can morph so rapidly into a ‘policy’ that becomes ‘mandatory’.
"Keep Trying"
Post #1225627
Samuel Vella
Samuel Vella
Posted Thursday, December 22, 2011 2:56 AM
Old Hand
Group: General Forum Members
Last Login: Friday, May 03, 2013 2:54 AM
Points: 328,
Visits: 1,848
It can work the other way too, where something is promoted early in an article and then disparaged straight after. Of course, once a reader has read the for arguements, they feel that they understand the subject and decide not to read any more.
The waterfall accident:
http://pascal.gugenberger.net/thoughts/waterfall-accident.html
Post #1225647
David.Poole
David.Poole
Posted Thursday, December 22, 2011 3:11 AM
SSCrazy
Group: General Forum Members
Last Login: Thursday, May 16, 2013 3:16 PM
Points: 2,749,
Visits: 1,405
I very rarely use GOTO, in fact I cannot remember when I last used it.
If I have a large stored proc with a complex transaction then on failure of any part of the transaction I might use GOTO to jump to the ROLLBACK TRANSACTION code.
To be honest, TRY...CATCH handles most scenarios for me.
GOTO is useful when some processing logic results in a value that indicates that the rest of the transactional process should not proceed.
The alternative is to set a BIT variable to TRUE and after each step in the transaction set it to FALSE if the success criteria is not met.
Wrap each step in the transaction up in
IF @SuccessFLAG=1
BEGIN
...
END
LinkedIn Profile
Post #1225655
call.copse
call.copse
Posted Thursday, December 22, 2011 3:21 AM
Ten Centuries
Group: General Forum Members
Last Login: 2 days ago @ 6:33 AM
Points: 1,080,
Visits: 687
I think GOTO is great and like to employ it at every opportunity. How else do you sensibly structure conditional exit points?
Just kidding. I don't think I've ever felt the need in my SQL or code of any sort - save perhaps some error handling in Access if I can remember that far back? Anyway I would not be scared if I did need to use it it's fair to say.
Post #1225671
Andrew Watson-478275
Andrew Watson-478275
Posted Thursday, December 22, 2011 3:25 AM
SSC Eights!
Group: General Forum Members
Last Login: Yesterday @ 1:44 AM
Points: 953,
Visits: 1,875
I found myself using one just the other day, and although it was by far the neatest and most readable option for the logic I was using, I still felt the need to add an apology in the comments!
Like everything (even, dare I say it, cursors), it's got its place, but anything more than occasional use should be a pointer for closer scrutiny.
Post #1225674
Resender
Resender
Posted Thursday, December 22, 2011 4:22 AM
SSC Veteran
Group: General Forum Members
Last Login: Wednesday, March 27, 2013 8:55 AM
Points: 289,
Visits: 683
In an age when animal could still speak...
Ok, not that long ago, about 12 years ago I got my first programming lessons I used the GOTO instead of using OO functions.
Over the years as my knowledge of programming grew and my enthusiasm to program grew less, I started to replace the GOTO less.
I didn't even know that it was in the SQL options.
In programming I can think of one use to still use it, to quickly skip code your debugging but the project can no longer wait to go live.
Post #1225713
« Prev Topic
|
Next Topic »
21 posts, Page 1 of 3
1
2
3
»
»»
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.