Click here to Skip to main content
13,196,126 members (52,287 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


1 bookmarked
Posted 9 Oct 2011

GO Statement can also be used to Execute Batch of T-SQL Statement Multiple Times

, 25 May 2013
Rate this:
Please Sign up or sign in to vote.
GO Statement can also be used to execute batch of T-SQL statement multiple times


Till recently, I was under the impression that GO statement’s sole purpose is to convey to the SQL Server the end of a batch of T-SQL Statements. But recently, while searching for some SQL feature details, I landed on to the MSDN page for the GO statement. And to my surprise, I observed that GO statement also has an integer optional parameter, this parameter value signals SQL Server to execute the batch of T-SQL Statement prior to the GO statement to be executed for the specified number of times.

Let us understand this with the following simple example:

PRINT 'Hello'
GO 5

Result of executing the above statement is as follows:

Beginning execution loop
Batch execution completed 5 times

This statement is very handy for testing purposes and dev tasks, such as for testing purpose if we need to insert millions of records together, we can achieve this with simple two statements as explained in the above example.

Please correct me if my understanding is wrong. Comments are always welcome, hope this tip helped you. Visit my blog for such SQL tips/tricks and articles.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Basavaraj P Biradar
Technical Lead
India India

You may also be interested in...


Comments and Discussions

GeneralReason for my vote of 5 FINALLY, I see a purpose for the GO.... Pin
ii_noname_ii24-Oct-11 20:26
memberii_noname_ii24-Oct-11 20:26 
GeneralMSDN link Pin
Reiss24-Oct-11 0:54
memberReiss24-Oct-11 0:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.171019.1 | Last Updated 26 May 2013
Article Copyright 2011 by Basavaraj P Biradar
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid