Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Batch Delimiter(GO)

Author  Topic 

mmkrishna1919
Yak Posting Veteran

95 Posts

Posted - 2013-06-06 : 09:02:37
Hi Team,

MCTS SELF TRAINING KIT(exam 70-433) says:

"The batch delimiter for t-sql is GO .while parsing the code when sql server encounter a GO the batch is considered terminated and subsequent code is considered to be another batch.Even if the GO with in comment block sql server still interpreted as batch delimiter"

I tried as below
go
declare @var int
set @var=10
select @var
/* testing GO as batch delimiter*/
select @var

i am getting output as
10
10

if GO in commented text will act as batch delimiter i should get an error like "Must declare the scalar variable "@var"."

Need clarification on whether GO will really act as batch delimiter even it is in comment block?

Thanks..

M.MURALI kRISHNA

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2013-06-06 : 09:26:25
Your test has given the answer to you


Too old to Rock'n'Roll too young to die.
Go to Top of Page

ditch
Master Smack Fu Yak Hacker

1466 Posts

Posted - 2013-06-06 : 09:29:13
This may have changed in a later version of sql, as I have had first hand experience in 2000 where this caused some problems, when I test it on my 2008 box now I can't seem to replicate the problem.

Duane.
Go to Top of Page

mmkrishna1919
Yak Posting Veteran

95 Posts

Posted - 2013-06-06 : 10:31:50
quote:
Originally posted by webfred

Your test has given the answer to you


Too old to Rock'n'Roll too young to die.




Thanks webfred and ditch..


M.MURALI kRISHNA
Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2013-06-06 : 10:46:38
Funny - I clearly remember having an issue with commented GOs. It must have been prior to sql 2005 though because now I don't see the issue.

I know that at one time this was treated correctly as a comment:
--GO
But this resolved to a batch terminator:
/*
GO
*/



Be One with the Optimizer
TG
Go to Top of Page

mmkrishna1919
Yak Posting Veteran

95 Posts

Posted - 2013-06-06 : 10:53:17
Yes TG..
it's interesting..
/*
Go
*/
In 2008 acts as commented block only
But in 2000 it acts as batch delimiter

Thanks...


M.MURALI kRISHNA
Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2013-06-06 : 11:05:59
Thanks for the confirmation.
I remember I was very happy when, I guess it was Query Analyzer at the time, introduced the ability to comment all selected lines at once with <cntr>+K,C. Because enclosing the block with /*<block>*/ didn't work if there were GOs in there.

Be One with the Optimizer
TG
Go to Top of Page
   

- Advertisement -