Importance of GO in T-SQL


Importance of GO in T-SQL

GO is a batch separator or terminator, it is not a T-SQL Statement or SQL keyword, that’s why it must be written in new line. 

Here is the example

There are two scenarios having one with GO and another is without it.

As you can see that when we execute left side window. DROP statement consider as part of the stored procedure. So stored procedure will be created and on first execution of that stored procedure that will be drop as stored procedure itself contain drop statement within it.

While on right side window, we placed a batch separator GO which separates that code in two batches:

  1. Create the stored procedure 
  2. Drops the stored procedure. so, executing this code drops stored procedure just after creation.

Using SQL server Management Studio, Tools -> Click on Options… and Select the Query Execution Tab.

There is a text-box with label Batch separator. you can change it from here.

Bhadresh Vasani
Bhadresh Vasani MVC, SQL Server, nodeJS, Web API, Power BI, JQuery, Javascript, C#