CREATE PROCEDURE with BEGIN/END

  • I found it surprising that a co-worker was having the GRANT EXECUTE included in his generated stored procedure when it was placed outside of the BEGIN/END statement. Placing a GO after the END fixed the problem, but why doesn't the END statement end the CREATE PROCEDURE?

    CREATE PROCEDURE dbo.blahblahblah

    @blah,

    @blah2

    AS

    BEGIN

    .......

    END

    GRANT EXECUTE on dbo.blahblahblah to blah_user

  • BEGIN and END are logical groupings and control flow statements within a TSQL statement. They aren't terminators to the SQL utility in the same way that GO is. So if you have to have a single script that contains the both the create statement and grant statements, you need to terminate each with the GO statement.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

Viewing 2 posts - 1 through 1 (of 1 total)

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