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.”
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.
- 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
Let me know your thoughts about the GO statement.
Reference: Pinal Dave (https://blog.sqlauthority.com)