• Sean Lange (12/4/2012)


    Shadab Shah (12/4/2012)


    anthony.green (12/4/2012)


    GO is a batch sperator.

    So you could say

    Do Something

    Do Something Else

    Do Something More

    GO

    Do Something Even More

    Do Something Better Than Before

    GO

    And it would execute the first three things in one batch, and the last two things in another batch.

    Without the GO's it would execute all 5 things in one batch

    Thanks antony for the reply but since i am relatively new to SQL Server, i was wondering in what scenario would we like the above mention thing to happen. I mean to say there is no conditional break and my objective is to excute all the 5 statement, so to me executing them one after another in sequence matter, why should i used GO.

    GO is ONLY used in SSMS. It is NOT a t-sql statement. It is a way to control what batches run. Think of a batch as something you would execute from another program. Consider the following code.

    declare @MyInt int = 42

    select @MyInt

    Select @MyInt / 2

    GO

    select @MyInt

    This all looks perfectly fine. Try running it. The last select statement is after the GO batch separator. That means the variable @MyInt is not in the current batch. The above will return 2 rows and error on the last select.

    Thanks sean that was indeed a very good example, cleared the concept clearly but has anybody used this in real application. I have never seen such GO written in between the lines of code in SP or in that matter in any other script