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!