Another use of GO command in SQL Server 2005

Published 06 August 08 07:07 AM | Madhivanan 

As you all know, GO command signals the end of the batch of T-SQL statements

However in SQL Server 2005, it is also used to execute set of commands for a specified number of times

Consider that you want to create a table that should have hundred random integer values. You can the methods like the ones specified in http://sqlblogcasts.com/blogs/madhivanan/archive/2007/10/10/generating-random-numbers-part-ii.aspx or a while loop. You can also use GO command by specifying how many times it should run

create table #numbers(random_value int)
GO -- Signals the end of the batch

insert into #numbers(random_value) Select cast(100000*rand() as int)
GO 100 -- Signals that the above statement should run for 100 times

select random_value from #numbers

Now the table would have 100 random interger values

Filed under: , ,

Comments

# Other SQL Server Blogs around the Web said on August 6, 2008 2:18 AM:

As you all know, GO command signals the end of the batch of T-SQL statements However in SQL Server 2005

# SQL Server Transact-SQL (SSQA.net) : Another use of GO command in SQL Server 2005 said on August 6, 2008 3:05 AM:

PingBack from http://sqlserver-qa.net/blogs/t-sql/archive/2008/08/06/4722.aspx

Anonymous comments are disabled

Search

Go

This Blog

«August 2008»
SMTWTFS
272829303112
3456789
10111213141516
17181920212223
24252627282930
31123456

Syndication