THE SQL Server Blog Spot on the Web

Welcome to SQLblog.com - The SQL Server blog spot on the web Sign in | |
in Search

Greg Low (The Bit Bucket: IDisposable)

Ramblings of Greg Low (SQL Server MVP, MCM and Microsoft RD) - SQL Down Under

In SQLCMD mode, should CONNECT be an implicit batch separator?

Hi Folks,

I've been working with SQLCMD mode again today and one thing about it always bites me. If I execute a script like:

:CONNECT SERVER1

SELECT @@VERSION;

:CONNECT SERVER2

SELECT @@VERSION;

:CONNECT SERVER3

SELECT @@VERSION;

I'm sure I'm not the only person that would be surprised to see all three SELECT commands executed against SERVER3 and none executed against SERVER1 or SERVER2. If you think that's odd behavior, here's where to vote: https://connect.microsoft.com/SQLServer/feedback/details/611144/sqlcmd-connect-to-a-different-server-should-be-an-implicit-batch-separator#details

 

Published Monday, January 17, 2011 7:32 PM by Greg Low

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

 

Duray Akar said:

Try this :

:CONNECT SERVER1

SELECT @@VERSION;

go

:CONNECT SERVER2

SELECT @@VERSION;

go

:CONNECT SERVER3

SELECT @@VERSION;

go

May 12, 2011 3:56 PM
 

Greg Low said:

Hi Duray,

I know how to fix it but the issue is whether or not the current behavior is sensible. I don't think it is.

Regards,

Greg

May 16, 2011 8:54 PM
 

Michael said:

I ran into this issue today.  Very frustrating!

December 5, 2014 6:29 PM
 

SQLCMD mode is really interesting said:

While parsing and executing are two different things, in SQLCMD mode they both mean the same thing-EXECUTE

June 21, 2015 7:42 PM
 

Jayaram Krishnaswamy said:

BOL does not say much about SQLCMD mode. One need to experiment and verify. It is reasonable to use the batch separator.

June 22, 2015 11:20 PM
 

Greg Low said:

The outcome (as it presently works) is both bizarre and unexpected. I think it should be changed.

June 23, 2015 12:32 AM

Leave a Comment

(required) 
(required) 
Submit

This Blog

Syndication

Tags

No tags have been created or used yet.
Powered by Community Server (Commercial Edition), by Telligent Systems
  Privacy Statement