In Sql server does "GO" have the same point and comma function?

Asked

Viewed 1,310 times

3

What is the reserved word "GO" for Sql Server, when generating a script using Sql Server Management is always generated with the reserved word "GO" at the end of the instructions, however if I take the same query and execute without the word "GO" it is executed normally.

I understand the use of the point and comma in the MySql, i understand that when running a query using a system with graphical interface this same system runs it with the period and comma at the end, even if I do not put it, and I also understand that it serves to separate the instructions, in the Sql Server the word "GO" has the same point and comma function? And if he is responsible for another task, what would be?

1 answer

3


SQL Server - GO utility instructions

SQL Server provides commands that are not Transact-SQL statements, but are recognized by the sqlcmd and osql utilities and the SQL Server Management Studio Code Editor. These commands can be used to facilitate readability and execution of batches and scripts.

GO signals the termination of a batch of Transact-SQL statements for SQL Server utilities.

GO goes beyond a dot and a comma

We can see this in this example

SELECT DB_NAME();  
SELECT USER_NAME();  
GO 2 

Note that there is a "2" in front of the "GO", this means that the above two instructions will be executed twice

Look at this other example

USE AdventureWorks2012;  
GO  
DECLARE @NmbrPeople int  
SELECT @NmbrPeople = COUNT(*)  
FROM Person.Person;  
PRINT 'The number of people as of ' +  
      CAST(GETDATE() AS char(20)) + ' is ' +  
      CAST(@NmbrPeople AS char (10));  
GO     

Where we have two blocks of instructions, where we have in the second block with local variables, which will be used only in this context since it was limited by "GO"

Source

Browser other questions tagged

You are not signed in. Login or sign up in order to post.