+1 vote
in Sql by
What is the use of GO in Transact SQL?

1 Answer

0 votes
by

The GO command isn't a Transact-SQL statement, but a special command recognized by several MS utilities including SQL Server Management Studio code editor.

The GO command is used to group SQL commands into batches which are sent to the server together. The commands included in the batch, that is, the set of commands since the last GO command or the start of the session, must be logically consistent. For example, you can't define a variable in one batch and then use it in another since the scope of the variable is limited to the batch in which it's defined.

Sometimes, you need a GO - e.g. if you add a column to a table, and then want to select it again, you need to have a GO between the adding of the column, and the query of it. The point is SSMS is trying to verify the whole statement at once, but on the SELECT statement, it will complain about the missing selected column.

Related questions

0 votes
+2 votes
asked Jan 15, 2022 in Sql by GeorgeBell
+2 votes
+1 vote
asked Jan 14, 2022 in Sql by GeorgeBell
...