Sunday, June 14, 2009

T-SQL Batch Seperator - GO [number]

As you know 'GO' is a T-SQL batch seperator command and it is not
T-SQL statement.It is a command recognized by the 'sqlcmd' and
'osql' utilities and SQL Server Management Studio Code editor.
There is nice feature that exists in SQL 2005 and above:

GO [number].
Where [number] is a positive integer.
For example,the below command will be executed 5 times:

SELECT * FROM sys.dm_os_performance_counters
GO 5

In Fact, all statements before the last GO and the start
of the ad hoc session or previous 'GO' statement will be executed

specified number of times.
The statement can also be Stored Procedure or any T-SQL command:

EXEC sp_who2
GO 2


Reference:
http://msdn.microsoft.com/en-us/library/ms188037.aspx

No comments:

Post a Comment