Reputation: 341
I heard that GO
statement separates the command batches in SQL. And the CREATE
transaction should be the only query on a batch.
But when i try:
Create database dbTest
Create table tbSomething(ID int primary key,Name varchar(30))
GO
The output is still SUCCESS.
So how does the GO
Statement affect the SQL batches?
Upvotes: 2
Views: 1518
Reputation: 45
'GO' statement in SQL server is to just sends a signal to take the current batch of SQL statements for execution.
To tell in simple words, it works like a delimiter.
It is an indication of end of SQL statement [i.e., 1 batch that needs to be executed].
Upvotes: 2
Reputation: 35613
GO
is used to divide a script into multiple batches.The word GO
is not a sql statement. It is understood by the SQL batch processor (for example SSMS) not by SQL Server.
Simply put, if GO
appears on a line on its own, SSMS sends each section delimited by GO
as a separate batch. SQL Server never sees the GO
lines, only the SQL between them.
Because SQL Server has a syntactic rule that stored procedures must be defined in a batch on their own, you will often find database creation scripts which use GO
to delimit the batches so that multiple stored procedures can be created from one script. However it is the client software which understands GO
and divides the batches, not SQL server.
Upvotes: 9