Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 GO keyword

Author  Topic 

Alexander Barnes
Starting Member

10 Posts

Posted - 2009-02-14 : 21:10:55
What does GO do in this script ... or why would you use it?

1> create table employee(
2> ID int,
3> name nvarchar (10),
4> salary int,
5> start_date datetime,
6> city nvarchar (10),
7> region char (1))
8> GO
1>
2> insert into employee (ID, name, salary, start_date, city, region)
3> values (1, 'Jason', 40420, '02/01/94', 'New York', 'W')
4> GO

(1 rows affected)

...repeats inserts as above...

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2009-02-14 : 23:20:13
GO is the batch separator - an instruction that the set of T-SQL instructions preceding the GO command should be sent to the server.

This means, for example, that the scope of a variable ends with the GO command.

GO is not a T-SQL command. It is just a batch separator. You can change it if you like - in SQL 2005, in Management Studio, in Tools -> Options -> Query Execution.

GO nnn can be used to indicate that the preceding batch should be executed nnn times. For example:
print 'Hello'
GO 10
would print the word Hello ten times.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-15 : 21:20:48
also see this

http://sqlblogcasts.com/blogs/madhivanan/archive/2008/08/06/another-use-of-go-command-in-sql-server-2005.aspx
Go to Top of Page

Alexander Barnes
Starting Member

10 Posts

Posted - 2009-02-17 : 23:02:06
Thank you...that makes sense. Appreciate the concise explanation and links to more info.

Alex.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-17 : 23:47:56
welcome
Go to Top of Page
   

- Advertisement -