Begin/End block for Entire Stored Procedure

  • Out of habit (or because my T-SQL "instructor" always did it) I have always encased my stored procedures in an BEGIN/END block, like this:

    CREATE PROCEDURE dbo.usp_get_group_list

    @group_id INT

    AS

    BEGIN

    ...

    ...

    ...

    END

     

    I just assumed it had to be that way, until a developer asked me a question about one of his SPs, and I noticed that he didn't code it that way.  Is there any reason (technical, personal preference, readability) to include Begin/End blocks like this?  It doesn't seem like it to me...

     

  • I think it is a personal preference.

     

    mom

  • I think that other development programs/system REQUIRE this however, MS SQL doesn't.  Depending on what shop you are in it may be a part of the company policy but SQL doesn't care (at the moment)



    Good Hunting!

    AJ Ahrens


    webmaster@kritter.net

  • Personally, I think it's a great idea to include the block around the stored procedure. 

    Why?  Well, as future versions of SQL come out and the lines between Transact-SQL and pure CLR code begin to blur, we will begin to see the symmetry between a standard “chunk” of pure code like:

    // C#

    public void MyFunction()

    {

                // Implementation Here

    }

    -- or --

    ' VB

    Public Sub MySubroutine()

          ' Implementation Here

    End Sub

     

    and the "chunk of code" that is a SQL stored procedure. 

     

    - john

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply