• It would not work inside a stored proc. It would end the batch. 🙂

    For example if you have a script that create a stored proc and a view you HAVE to use a batch separator.

    Take a look at this.

    create proc MyProc as

    begin

    select 1

    end

    create view MyView as

    (

    select top 5 * from sys.columns

    )

    These are obviously greatly simplified but serves the point. This script won't run and you will get an "incorrect syntax" exception. If you mouse over the red squiggly line for the create view line it will tell that "CREATE VIEW must be the only statement in the batch".

    So to save us the hassle of making us open every single statement in a new window we have a batch separator. Here is the same proc and view but I added GO so it will run. I also added drop statements at the end.

    create proc MyProc as

    begin

    select 1

    end

    GO

    create view MyView as

    (

    select top 5 * from sys.columns

    )

    GO

    drop procedure MyProc

    drop view MyView

    This type of thing is often used for deployment scripts or other times you need to execute multiple batches at one time.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/