钢板下料排版破解软件:请问SQL语句中go有什么作用?

来源:百度文库 编辑:神马品牌网 时间:2024/05/08 05:52:18

查看sql的帮助即可,很详细地说。

GO
Signals the end of a batch of Transact-SQL statements to the Microsoft® SQL Server™ utilities.

Syntax
GO

Remarks
GO is not a Transact-SQL statement; it is a command recognized by the osql and isql utilities and SQL Query Analyzer.

SQL Server utilities interpret GO as a signal that they should send the current batch of Transact-SQL statements to 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. SQL Query Analyzer and the osql and isql command prompt utilities implement GO differently. For more information, see osql Utility, isql Utility, and SQL Query Analyzer.

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.

USE pubs
GO
DECLARE @MyMsg VARCHAR(50)
SELECT @MyMsg = 'Hello, World.'
GO -- @MyMsg is not valid after this GO ends the batch.

-- Yields an error because @MyMsg not declared in this batch.
PRINT @MyMsg
GO

SELECT @@VERSION;
-- Yields an error: Must be EXEC sp_who if not first statement in
-- batch.
sp_who
GO

SQL Server applications can send multiple Transact-SQL statements to SQL Server for execution as a batch. The statements in the batch are then compiled into a single execution plan. Programmers executing ad hoc statements in the SQL Server utilities, or building scripts of Transact-SQL statements to run through the SQL Server utilities, use GO to signal the end of a batch.

Applications based on the DB-Library, ODBC, or OLE DB APIs receive a syntax error if they attempt to execute a GO command. The SQL Server utilities never send a GO command to the server.

Permissions
GO is a utility command that requires no permissions. It can be executed by any user.

Examples
This example creates two batches. The first batch contains only a USE pubs statement to set the database context. The remaining statements use a local variable, so all local variable declarations must be grouped in a single batch. This is done by not having a GO command until after the last statement that references the variable.

USE pubs
GO
DECLARE @NmbrAuthors int
SELECT @NmbrAuthors = COUNT(*)
FROM authors
PRINT 'The number of authors as of ' +
CAST(GETDATE() AS char(20)) + ' is ' +
CAST(@NmbrAuthors AS char (10))
GO

GO 0202 用信号通知 02 Microsoft® 02 SQL 02 Server™ 02 实用工具一批 02 Transact-SQL 02 语句的结束。 0202 0202 语法 02
02 GO 0202 0202 注释 02
02 GO 02 不是 02 Transact-SQL 02 语句;而是可为 02 osql 02 和 02 isql 02 实用工具及 02 SQL 02 Server 02 查询分析器识别的命令。 0202 0202 SQL 02 Server 02 实用工具将 02 GO 02 解释为应将当前的 02 Transact-SQL 02 批处理语句发送给 02 SQL 02 Server 02 的信号。当前批处理语句是自上一 02 GO 02 命令后输入的所有语句,若是第一条 02 GO 02 命令,则是从特殊会话或脚本的开始处到这条 02 GO 02 命令之间的所有语句。SQL 02 查询分析器和 02 osql 02 及 02 isql 02 命令提示实用工具执行 02 GO 02 命令的方式不同。有关更多信息,请参见 02 osql 02 实用工具、isql 02 实用工具和 02 SQL 02 查询分析器。 02 0202 0202 GO 02 命令和Transact-SQL 02 语句不可在同一行上。但在 02 GO 02 命令行中可包含注释。 0202 0202 用户必须遵照使用批处理的规则。例如,
在批处理中的第一条语句后执行任何存储过程必须包含 02 EXECUTE 02 关键字。局部(用户定义)变量的作用域限制在一个批处理中,
不可在 02 GO 02 命令后引用。 0202 0202 USE 02 pubs 02
02 GO 02
02 DECLARE 02 @MyMsg 02 VARCHAR(50) 02
02 SELECT 02 @MyMsg 02 = 02 'Hello, 02 World.' 02
02 GO 02 -- 02 @MyMsg 02 is 02 not 02 valid 02 after 02 this 02 GO 02 ends 02 the 02 batch. 0202 0202 -- 02 Yields 02 an 02 error 02 because 02 @MyMsg 02 not 02 declared 02 in 02 this 02 batch. 02
02 PRINT 02 @MyMsg 02
02 GO 0202 0202 SELECT 02 @@VERSION; 02
02 -- 02 Yields 02 an 02 error: 02 Must 02 be 02 EXEC 02 sp_who 02 if 02 not 02 first 02 statement 02 in 02 02
02 -- 02 batch. 02
02 sp_who 02
02 GO 0202 0202 SQL 02 Server 02 应用程序可将多条 02 Transact-SQL 02 语句作为一个批处理发给 02 SQL 02 Server 02 去执行。在此批处理中的语句编译成一个执行计划。程序员在 02 SQL 02 Server 02 实用工具中执行特定语句,或生成 02 Transact-SQL 02 语句脚本在 02 SQL 02 Server 02 实用工具中运行,用 02 GO 02 来标识批处理的结束。 0202 0202 如果基于 02 DB-Library、ODBC 02 或 02 OLE 02 DB 02 APIs 02 的应用程序试图执行 02 GO 02 命令时会收到语法错误。SQL 02 Server 02 实用工具永远不会向服务器发送 02 GO 02 命令。 0202 0202 权限 02
02 GO 02 是一个不需权限的实用工具命令。可以由任何用户执行。 0202 0202 示例 02
02 下面的示例创建两个批处理。第一个批处理只包含一条 02 USE 02 pubs 02 语句,用于设置数据库上下文。剩下的语句使用了一个局部变量,
因此所有的局部变量声明必须在一个批处理中。
这一点可通过在最后一条引用此变量的语句之后才使用 02 GO 02 命令来做到。 0202 0202 USE 02 pubs 02
02 GO 02
02 DECLARE 02 @NmbrAuthors 02 int 02
02 SELECT 02 @NmbrAuthors 02 = 02 COUNT(*) 02
02 FROM 02 authors 02
02 PRINT 02 'The 02 number 02 of 02 authors 02 as 02 of 02 ' 02 + 02
02 02 02 02 02 02 02 CAST(GETDATE() 02 AS 02 char(20)) 02 + 02 ' 02 is 02 ' 02 + 02
02 02 02 02 02 02 02 CAST(@NmbrAuthors 02 AS 02 char 02 (10)) 02

简单的说 去 执行GO上面的操作

分隔命令