GO is not a Transact-SQL statement; it is a command recognized by the sqlcmd and osql utilities and SQL Server Management Studio Code editor.
SQL Server utilities interpret GO as a signal that they should send the current batch of Transact-SQL statements to an instance of SQL Server. The current batch of statements is composed of all statements entered since the last GO, or since the start of the ad hoc session or script if this is the first GO.
The scope of local (user-defined) variables is limited to a batch, and cannot be referenced after a GO command.
declare @a int
select @a=100
print @a
GO -- @MyMsg is not valid after this GO ends the batch.
print @a
one more use of GO
The batch preceding GO will execute the specified number of times.
with the GO , below insert query runs 100 times.
create table test(a integer)
insert into test values(1)
go 100
No comments:
Post a Comment