T-SQL keywords go

Source: Internet
Author: User
Tags sql server query
Transact-SQL reference


Use a signal to notify Microsoft SQL server of the completion of a batch of transact-SQL statements.




Go is not a Transact-SQL statement.OsqlAndISQLUtility and SQL Server Query analyzer recognition commands.

The SQL Server utility interprets go as a signal that the current Transact-SQL batch processing statement should be sent to SQL Server. The current batch processing statement is all the statements entered after the previous go command. If it is the first go command, it is all the statements from the beginning of a special session or script to the beginning of this go command. SQL query analyzer andOsqlAndISQLThe command prompts the utility to execute the go command in different ways. For more information, see osql utility, iSQL utility, and SQL query analyzer.

The go command and the transact-SQL statement cannot be on the same line. However, the go command line can contain comments.

You must follow the batch processing rules. For example, after the first statement in the batch processing, any stored procedure must contain the execute keyword. The scope of local (User-Defined) variables is limited to one batch and cannot be referenced after the go command.

Use pubsgodeclare @ mymsg varchar (50) Select @ mymsg = 'hello, world. 'Go -- @ mymsg is not valid after this go ends the batch. -- yields an error because @ mymsg not declared in this batch. print @ mymsggoselect @ version; -- yields an error: Must be exec sp_who if not first statement in -- batch. sp_whogo

SQL Server ApplicationProgramMultiple Transact-SQL statements can be sent to SQL Server for execution as a batch. The statements in this batch are compiled into an execution plan. The programmer executes a specific statement in the SQL Server utility or generates a Transact-SQL statement script to run in the SQL Server utility, and uses go to identify the end of batch processing.

If an application based on DB-library, ODBC, or ole db APIs tries to execute the go command, it will receive a syntax error. SQL Server utility never sends go commands to the server.


Go is a utility command without permissions. It can be executed by any user.


The following example creates two batches. The first batch contains only one usePubsStatement, used to set the database context. The remaining statement uses a local variable, so all local variable declarations must be in a batch. This can be done by using the go command only after the last statement that references this variable.

  Use pubsgodeclare @ nmbrauthors intselect @ nmbrauthors = count (*) from authorsprint 'the number of authors as of '+ Cast (getdate () as char (20 )) + 'is' + Cast (@ nmbrauthors as char (10) Go  
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.