RE:

  • I think this article illustrates a common misunderstanding of the syntax of sp definition. An sp is defined when the first statement of a batch is "create procedure" and includes all statements to the end of the batch. Additionally, there is no formal role for line ends or termination symbols to define each statement within a batch. A statement is essentially something that will parse as a statement. The word "go" on it's own line can be used to formally indicate the end of a batch to the input parser, but it's not part of the T-SQL language and never reaches the database engine.

    You're also wrapping the sp content in "begin..end" which gives the impression that these statements are required to formally define the sp and they are not (unlike for a function definition, where confusingly and annoyingly they are).

    Thus, the following horribly ugly code, is perfectly fine:

    create procedure proc1 as print 'batch 1' print 'end of batch 1'
    go
    print 'batch 2' print 'end of batch 2'
    go
    create procedure proc2 as print 'batch 3' print 'end of batch 3'

    This code executes three independent batches on the server, the first and last define a procedure, the second just causes output. The "go" statements must be their own lines --- it will not pass the parse check if they are run together with the SQL.

    Graham

    p.s. I'm not reccomending that anybody actually code like this, just remember that SQL Server wouldn't care if you did and the syntax has been designed to permit it. 😉

Viewing 0 posts

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