The role of batch go

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

--the parser will parse all the code before the next go before executing, even if the last step is wrong, it will roll back to the state of the first statement, in other words, the parser will put the statement between go as a transaction, and the error will be rolled back to the previous go.
--You can run the following code under the parser

CREATE TABLE Temp (myint int)
Go--When this go and the following go does not, although this statement is correct, but because of the following error, the table will not be created,
--when there is only this go, without the following go, the table temp will be created, even if the following statement is wrong.
Create function myfuntion (@int int)
Returns varchar (100)
As
Begin
DECLARE @intvar varchar (100)
Set @intvar = ' ASDFASD '
Return @intvar
End
Go-the statement will go wrong without this go, and the function will be created before the following statement can be executed.

SELECT [sdaf]= dbo.myfuntion (2)
Drop function Myfuntion
DROP TABLE Temp

Another example

CREATE TABLE Temp (myint int)
GO
Insert TBLTEMP1 values (' 1 ', ' 2 ', ' a ')
GO
CREATE TABLE Temp2 (myint int)
Insert TBLTEMP1 values (' 1 ', ' 2 ', ' a ')
--insert tbltemp values (' 1 ', ' 2 ')
CREATE TABLE Temp3 (myint int)
GO

Experience:

Batch processing will not execute if a compilation error is encountered;

The execution steps before running the error point in this batch will take effect and the statement following the run error point will not be executed when a run error is encountered.

Errors in this batch block do not affect the execution of other batch blocks!

If the script does not have a go statement, it means that the entire script block is a batch block!

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.