Interview Question of the Week #009 – Is GO T-SQL Statement?

I get this question by email more often than I would expect: Is GO a T-SQL statement? The answer is no. SSMS and tools such as sqlcmd recognize GO as a signal to send the preceding batch to SQL Server. The engine does not receive the word GO.

A music-box mechanism with separate cylinders for repeated passages

This short SSMS script makes the client behavior visible:

SELECT N'This batch is submitted again by the client.' AS BatchMessage;
GO 3
Real SSMS query with GO 3 and three result sets from repeating the same batch
The same batch was submitted three times. The SQL and all three real result sets are visible in this cursor-free SSMS capture.

The number after GO tells a supporting client to repeat the preceding batch. It does not copy and paste the statement into your script. That distinction matters if the batch changes data: GO 3 would run the change three times.

Two practical rules answer most follow-up questions. Put GO on its own line, with only an optional comment beside it, and do not add a T-SQL semicolon after it. Also, do not send a script containing GO as one command through an application driver. An ODBC or OLE DB application needs to send separate batches or use a script-aware runner. Local variables also stop at a batch boundary.

SSMS lets you change its batch-separator word, another reminder that this belongs to the client tool. My older explanation of the SQL command GO covers the same distinction. For an interview, the one-sentence answer is enough: GO ends a client-side batch; it is not T-SQL sent to SQL Server.

The client chooses the separator

Original SSMS Options dialog shows Query Execution batch separator set to GO
The original SSMS Options capture shows its batch-separator setting. This is historical interface evidence, separate from the current GO 3 result above.

Published by Pinal Dave on SQLAuthority. More of my work at pinaldave.com.


Discover more from SQL Authority with Pinal Dave

Subscribe to get the latest posts sent to your email.

SQL Command, SQL Scripts, SQL Server
Previous Post
Interview Question of the Week #008 – Write Scripts to Convert String to Title Case or Proper Case
Next Post
Interview Question of the Week #010 – What is the Difference Between Primary Key Constraints and Unique Key Constraints?

Related Posts

13 Comments. Leave new

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.