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

I often get this question in the email – more frequently than I would like to get. Let us see a simple question about GO T-SQL Statement or not.

Question: “Is GO T-SQL statement?”

Answer: “No, GO is not a T-SQL statement, it is a command which is recognized by SSMS or sqlcmd as a signal to send the current batch to SQL Server Engine.”

Well, here are two articles I recommend to read for more information – MSDN and Explanation SQL Command GO.

Here are few things I would like to add related to the GO statement.

  • If recommend a statement terminator semicolon after each statement, however, do not use semicolon after the GO statement or it will give an error.
  • ODBC or OLE DB API does not recognize the GO statement and it will give a syntax error.
  • You can use GO in a next line of T-SQL Statement. If you provide an integer after GO statement, it will execute that statement multiple times.
    SQLQuery1.sql report with 1 row and 1 column showing results.
  • You can only have comments in the same line as a GO statement, any other statement will error.
  • You can change the command GO to any other value in SSMS by going to Tools > Option
    GO T-SQL Statement Options.

Let me know your thoughts about the GO statement.

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

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.