locked
What is the use of GO statement in sql statements ?? RRS feed

  • Question

  • Hi,

    In most of the set of sequential querys we are using GO statement at the end of the each statement.

    Is it any use of this statement in performance wise ??

    Appreciate your response...

    Thanks,

    TNBabu


    TNBabu

    Wednesday, December 30, 2015 9:52 AM

Answers

  • GO is the default batch terminator in SSMS. It's not a statement.

    SQL statements separated by GO in SSMS are executed as separated batches. Thus they have a different scope and transaction boundary.

    So your question makes not really sense, cause it is not related to performance in the first place.

    • Proposed as answer by Tom Phillips Wednesday, December 30, 2015 7:06 PM
    • Marked as answer by TNBabu Thursday, December 31, 2015 5:02 AM
    Wednesday, December 30, 2015 10:04 AM
  • Well, but I need to say that: You're almost completely wrong.

    GO is NOT a SQL command.

    It is not used to execute multiple queries as batch, it is used to separate (different group of) statements to run them in different batches.

    10 statements without go are execute as one batch. Using the GO after each statement will lead to ten executed batches. Thus using GO increases the server round-trip.

    • Marked as answer by TNBabu Thursday, December 31, 2015 5:02 AM
    Wednesday, December 30, 2015 1:41 PM
  • A simple search led me to lot of articles

    https://msdn.microsoft.com/en-us/library/ms188037(v=sql.110).aspx

    http://stackoverflow.com/questions/2299249/what-is-the-use-of-go-in-sql-server-management-studio-transact-sql

    It has nothing to do with performance at all


    Please mark this reply as answer if it solved your issue or vote as helpful if it helped so that other forum members can benefit from it

    My Wiki Articles

    MVP


    Wednesday, December 30, 2015 10:15 AM

All replies

  • GO is the default batch terminator in SSMS. It's not a statement.

    SQL statements separated by GO in SSMS are executed as separated batches. Thus they have a different scope and transaction boundary.

    So your question makes not really sense, cause it is not related to performance in the first place.

    • Proposed as answer by Tom Phillips Wednesday, December 30, 2015 7:06 PM
    • Marked as answer by TNBabu Thursday, December 31, 2015 5:02 AM
    Wednesday, December 30, 2015 10:04 AM
  • A simple search led me to lot of articles

    https://msdn.microsoft.com/en-us/library/ms188037(v=sql.110).aspx

    http://stackoverflow.com/questions/2299249/what-is-the-use-of-go-in-sql-server-management-studio-transact-sql

    It has nothing to do with performance at all


    Please mark this reply as answer if it solved your issue or vote as helpful if it helped so that other forum members can benefit from it

    My Wiki Articles

    MVP


    Wednesday, December 30, 2015 10:15 AM
  • GO is a SQL command to execute multiple query as a batch, and batch is nothing but a collection of queries which will send a single request to execute to SQL server. Suppose you have 10 number of query and want to execute together, so if you are executing without GO command it will execute without any error but the query will send request 10 time to SQL server which will increase network traffic. But using GO command you can achieve same task with only one request to SQL server. So always use GO(recommended) when executing n number of query together.

    Wednesday, December 30, 2015 10:47 AM
  • GO Statement must be written in new line as it is not T-SQL command. T-SQL statement can not occupy the same line as GO.

    it is not related to performance.

    http://blog.sqlauthority.com/2007/05/11/sql-server-explanation-sql-command-go/


    Please click Mark As Answer if my post helped.

    Wednesday, December 30, 2015 11:19 AM
  • Well, but I need to say that: You're almost completely wrong.

    GO is NOT a SQL command.

    It is not used to execute multiple queries as batch, it is used to separate (different group of) statements to run them in different batches.

    10 statements without go are execute as one batch. Using the GO after each statement will lead to ten executed batches. Thus using GO increases the server round-trip.

    • Marked as answer by TNBabu Thursday, December 31, 2015 5:02 AM
    Wednesday, December 30, 2015 1:41 PM