Re: GO ...?
- From: WCM <WCM@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Sat, 22 Aug 2009 08:40:01 -0700
Hi Hugo,
Your resonse was very helpful. Thank you. So it seems GO is purely a
client side command, which makes sense. If client doesn't support GO, then
it is a non-issue.
But even inside QA (or 2005 query pane), without GO, is there ever a danger
in sql server not processing code sequentially (i.e., processing a subsequent
line prior to completely processing a prior line)? I have never run into
that problem.
Assuming I want my 300 lines of code (test for temp table existence > create
temp tables > do table joins and insert temp table data > update temp table
data > return results) to run top to bottom, sequentially, is there a
necessity for GO? I know I can use it, but is it ever a requirement to make
script run right? Assume variable scope is not an issue.
Thanks again for you help ...
Bill
"Hugo Kornelis" wrote:
On Sat, 22 Aug 2009 07:24:01 -0700, WCM wrote:.
Hi Andrew,
Thanks for your reply.
I don't use GO statements as I have always assumed sql server will process
my T-Sql one line at a time, and it will finish processing that line before
moving on to the next. In other words, if my #temp table 'create table'
statement appears before my 'insert' statement, sql server will always create
the table before executing the 'insert' statement. And if my 'update'
statement appears after the 'insert statement', sql server will always insert
all data before executing the 'update'. I have never run into a problem with
this assumption.
Am I missing something? As long as my code is sequentially logical, should
I be concerned with processing it all as one 'batch' (i.e., with no GO
statement)?
Also, one of my clients uses ColdFusion with sql server backend. I don't
believe GO statements are allowed in ColdFusion pass through queries.
Thanks again for your clarification ... much appreciated.
Hi Bill,
To cllarify, GO is not a SQL statement. It is a special code, recognised
by most front end clients, to signify the end of the batch. In other
words, GO means to the front end: "Stop here, and send the commands up
till now to the server. Only start submitting the next batch after the
server returns from this one". If you use a client that doesn't use the
GO terminator, and you still embed it in your code, you'll get syntax
errors as SQL Server itself doesn;t recognise it as a valid keyword.
There are cases where you need to seperate your code in batches. For
instance, a CREATE PROCEDURE statement must be the first in a batch, and
everything that follows it until the end of the batch is interpreted as
being part of that procedure, so if you need to do more actions after
creating the procedure, you need a batch seperator.
On the other hand, there are also cases where you must not put commands
into seperate batches. Variable declarations always last until the end
of the batch, so if you put a GO between the variable declaration and
the use of that variable, you'll get an error in the second batch
because the variable is no longer declared.
I hope this helps.
--
Hugo Kornelis, SQL Server MVP
My SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
- Follow-Ups:
- Re: GO ...?
- From: Erland Sommarskog
- Re: GO ...?
- From: --CELKO--
- Re: GO ...?
- References:
- GO ...?
- From: WCM
- Re: GO ...?
- From: Andrew J. Kelly
- Re: GO ...?
- From: WCM
- Re: GO ...?
- From: Hugo Kornelis
- GO ...?
- Prev by Date: Re: ALTER COLUMN ISSUE
- Next by Date: Re: GO ...?
- Previous by thread: Re: GO ...?
- Next by thread: Re: GO ...?
- Index(es):
Relevant Pages
|
Loading