Gene Wirchenko
2012-05-30 21:21:01 UTC
Dear SQLers:
I am somewhat confused about when to use GO. I would like to
avoid it where possible, that is, I would prefer to make my batches as
big as possible. Trying to find out when GO can be omitted is a bit
of an adventure.
I have done Web searching to find an answer, but there is not
enough detail, as in, for example:
http://msdn.microsoft.com/en-us/library/ms188037.aspx
I have a script where I very early delete the database and
recreate it. In one recent problem area, I create a procedure. It
has a GO in front of it, because stored procedures have to be first in
a batch. Fine. If I then follow with a CREATE TABLE in the same
batch, I get an error that seems to indicate that the CREATE TABLE has
been included in the procedure. If I put a GO just after the
procedure, I do not have this problem.
What am I missing or misunderstanding?
(I am now putting each of my CREATE PROCEDURE statements (and the
procedure) in its own batch delimited by GO at both the beginning and
the end. This is a bit cargo cult, but it works.)
When exactly is GO required?
Sincerely,
Gene Wirchenko
I am somewhat confused about when to use GO. I would like to
avoid it where possible, that is, I would prefer to make my batches as
big as possible. Trying to find out when GO can be omitted is a bit
of an adventure.
I have done Web searching to find an answer, but there is not
enough detail, as in, for example:
http://msdn.microsoft.com/en-us/library/ms188037.aspx
I have a script where I very early delete the database and
recreate it. In one recent problem area, I create a procedure. It
has a GO in front of it, because stored procedures have to be first in
a batch. Fine. If I then follow with a CREATE TABLE in the same
batch, I get an error that seems to indicate that the CREATE TABLE has
been included in the procedure. If I put a GO just after the
procedure, I do not have this problem.
What am I missing or misunderstanding?
(I am now putting each of my CREATE PROCEDURE statements (and the
procedure) in its own batch delimited by GO at both the beginning and
the end. This is a bit cargo cult, but it works.)
When exactly is GO required?
Sincerely,
Gene Wirchenko