Click here to monitor SSC
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in
Home       Members    Calendar    Who's On

Add to briefcase

RE: Expand / Collapse
Posted Tuesday, February 21, 2006 8:27 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Tuesday, June 23, 2009 1:04 PM
Points: 72, Visits: 9

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'
print 'batch 2' print 'end of batch 2'
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.


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.

Post #260226
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse