Reply to Re: Basic Questions

Your name:

Reply:


Posted by Erland Sommarskog on 02/14/07 22:40

BJMurphy (murphy.ben@gmail.com) writes:
> To clarify further, if I use a semi-colon at the end of my query, and
> put several queries in a row, SQL server will not execute them until
> it reaches the end of the set of queries or a "GO" statement. Is that
> correct?

Not really. SQL Server never reaches any GO statement. GO is not a statement
at all. GO carries no particular meaning for SQL Server at all. GO is a
separator that is intercepted by interactive query tools. You would
never have any GO in a program.

Keep in mind that SQL Server is a client-server application. Query
Analyzer or SQL Server Management Studio are not SQL Server. They
are client tools. When you select a couple of statements in a
query window, they will send these to SQL Server. But if there are
GO on some lines, they will send the batches one by one. And one
batch will not be sent, until the previous has executed.

Once in SQL Server, SQL Server will execute the statements, sequentially.
(Unless there is some control-of-flow languages.)

The semi-colons are statement terminators, but in difference to
other semicolon languages, they are optional in SQL Server. (Except in
a few situations where they are needed to disambiguiate the grammar.)

> Put another way, if I am creating table A in one query and then want
> to use it in the next query, do I have any options other than using
> "GO" after the first query to ensure that table A will be available in
> the second query?

There are statements that must be alone in a batck, like CREATE PROCEDURE
and CREATE VIEW. So to refer to you newly created view, you need to
do this in a separate batch. There are also some commands that does not
take effect until the next batch. Some SET commands are like that.

However, CREATE TABLE does not have any of these quirks. You can say:

CREATE #mytable (a int NOT NULL
INSERT #mytable(a) VALUES (213)

--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация