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:
- Create the stored procedure
- 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.