0

Possible Duplicate:
What is the use of GO in SQL Server Management Studio?

I have some Data Manipulation Language like below.

Case - 1 Without GO

Update Table
Set Columns = 'Value'
Where Id = 1

Update Table
Set Columns = 'Value'
Where Id = 2

Case - 2 With GO

Update Table
Set Columns = 'Value'
Where Id = 1

GO

Update Table
Set Columns = 'Value'
Where Id = 2

Query

Which should be preferred and why ?

Community
  • 1
  • 1
Pankaj
  • 9,749
  • 32
  • 139
  • 283
  • 1
    If you disagree with this being a duplicate, state so in the comments and explain your point of view. But please don't just remove the "Possible duplicate" link at the top of the post. – Heinzi Feb 16 '12 at 08:22

3 Answers3

0

The only difference - that the 1st query runs in one turn since 2nd - in tho turns. GO delimiter is not a server command, it is just a batch separator, which should be handled by client.

This means - that 1st query performs better because of 1-turn query

Oleg Dok
  • 21,109
  • 4
  • 45
  • 54
0

Refer below url it may help you.

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

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.

A Transact-SQL statement cannot occupy the same line as a GO command. However, the line can contain comments.

Users must follow the rules for batches. For example, any execution of a stored procedure after the first statement in a batch must include the EXECUTE keyword. The scope of local (user-defined) variables is limited to a batch, and cannot be referenced after a GO command.

Oleg Dok
  • 21,109
  • 4
  • 45
  • 54
Sanjay Goswami
  • 1,386
  • 6
  • 13
0

I got the differences in terms of Stored Procedure.

Case 1 - When Select 2 is not the part and explicitly seperated from this stored procedure

Create proc abc
as
select 1

GO

select 2

Case 2 - When Select 2 is not the part of stored Procedure and by mistake became the part of stored procedure due to absence of GO

Create proc abc
as
select 1

select 2

In case 2 , Definition of the language becomes following.

Create proc abc
as
select 1

select 2
Pankaj
  • 9,749
  • 32
  • 139
  • 283