SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Creating Your First Stored Procedure


Creating Your First Stored Procedure

Author
Message
Steve Jones
Steve Jones
SSC Guru
SSC Guru (651K reputation)SSC Guru (651K reputation)SSC Guru (651K reputation)SSC Guru (651K reputation)SSC Guru (651K reputation)SSC Guru (651K reputation)SSC Guru (651K reputation)SSC Guru (651K reputation)

Group: Administrators
Points: 651197 Visits: 21472
Comments posted to this topic are about the item Creating Your First Stored Procedure

Follow me on Twitter: @way0utwest
Forum Etiquette: How to post data/code on a forum to get the best help
My Blog: www.voiceofthedba.com
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (936K reputation)SSC Guru (936K reputation)SSC Guru (936K reputation)SSC Guru (936K reputation)SSC Guru (936K reputation)SSC Guru (936K reputation)SSC Guru (936K reputation)SSC Guru (936K reputation)

Group: General Forum Members
Points: 936049 Visits: 49079
Great article, Steve.

My only quandary is where does the idea of it being preferable to include BEGIN/END come from? Oracle? Portability? To be sure, I never include BEGIN/END in stored procedures mostly because it makes it more difficult to execute a part of the code during troubleshooting under the gun. You have to remember to comment out the BEGIN and then remember to uncomment it when you're done. It doesn't really bring anything to the game unless you know for sure that your code will be migrated to an RDBMS that requires it.

I also realize that it's a "Beginner's" article and so it's not designed to be all encompassing. I was happy to see the beginning of a "Flower Box" but both a more complete one and emphasizing that comments make code so much easier to troubleshoot would be good for beginners to understand.

--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.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

When you put the right degree of spin on it, the number 318 is also a glyph that describes the nature of a DBAs job. Wink

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
Luis Cazares
Luis Cazares
SSC Guru
SSC Guru (172K reputation)SSC Guru (172K reputation)SSC Guru (172K reputation)SSC Guru (172K reputation)SSC Guru (172K reputation)SSC Guru (172K reputation)SSC Guru (172K reputation)SSC Guru (172K reputation)

Group: General Forum Members
Points: 172730 Visits: 23044
Jeff Moden - Monday, February 4, 2019 6:00 AM
Great article, Steve.

My only quandary is where does the idea of it being preferable to include BEGIN/END come from? Oracle? Portability? To be sure, I never include BEGIN/END in stored procedures mostly because it makes it more difficult to execute a part of the code during troubleshooting under the gun. You have to remember to comment out the BEGIN and then remember to uncomment it when you're done. It doesn't really bring anything to the game unless you know for sure that your code will be migrated to an RDBMS that requires it.

I also realize that it's a "Beginner's" article and so it's not designed to be all encompassing. I was happy to see the beginning of a "Flower Box" but both a more complete one and emphasizing that comments make code so much easier to troubleshoot would be good for beginners to understand.

I totally agree. I've also seen beginners (sometimes with multiple years of "experience") wondering why there's some unexpected behavior with the procedure. The reason was that they thought that the code they wrote after the END wasn't going to be part of the procedure. This usually happens with a variable used in a SELECT for debugging or permissions granted in inappropriate environments.



Luis C.
General Disclaimer:
Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?


How to post data/code on a forum to get the best help: Option 1 / Option 2
Steve Jones
Steve Jones
SSC Guru
SSC Guru (651K reputation)SSC Guru (651K reputation)SSC Guru (651K reputation)SSC Guru (651K reputation)SSC Guru (651K reputation)SSC Guru (651K reputation)SSC Guru (651K reputation)SSC Guru (651K reputation)

Group: Administrators
Points: 651197 Visits: 21472
Re: Begin/end, I think this is a good programming practice and it shows that you intentionally put certain code in the procedure. If you're executing the code under the gun, I assume you're changing the parameters to a DECLARE? I would note that's likely a more advanced concept.

The "basics" is just that. I feel that sometimes we try to write all encompassing articles that become too long and confusing for someone that wants to get started. I'd like to see more developers start using these, and my view is that the ought to try and write some based on a quick introduction.

I may try to write something more advanced than this, but it's a question of time and resources. Someone else is welcome to do so if they like.

Follow me on Twitter: @way0utwest
Forum Etiquette: How to post data/code on a forum to get the best help
My Blog: www.voiceofthedba.com
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum









































































































































































SQLServerCentral


Search