i know the use of GO keyword. it sends multiple statements to sql server as a whole group, instead of sending each statement one by one. i hope i am right!
but i want to know that do programmers use it in real applications. like if we create a stored procedure, then that also does the same thing,it also compiles the code and make an execution plan , and send the whole group to the server.
so do we need to specify the GO keyword in the coding of database objects such as triggers, views, stored procedures ?
GO is a command used for signaling the end of a batch. Note that it is not a T-SQL statement.
Batch is a group of one or more Transact-SQL statements sent at the same time from an application to SQL Server for execution
GO is very useful in SQL Server. Though, you need to use it only when is really needed.
So, you need to keep in mind that along with defining a batch using the GO command, you define the scope of that specific piece of T-SQL code. The local variables defined in a batch are specific to that batch.
Scope example –
Running this will give you error saying @STRING2 is not declared. Because the scope of that variable ends with the GO. So beware of using GO and use smartly.
Source – http://aartemiou.blogspot.com/2009/08/using-go-command-in-sql-server.html