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


RE:


Author
Message
click-fund
click-fund
SSC Veteran
SSC Veteran (206 reputation)SSC Veteran (206 reputation)SSC Veteran (206 reputation)SSC Veteran (206 reputation)SSC Veteran (206 reputation)SSC Veteran (206 reputation)SSC Veteran (206 reputation)SSC Veteran (206 reputation)

Group: General Forum Members
Points: 206 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'
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. ;-)





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