SQL Server 查询分析器中的GO 是成对使用还是单独使用?
答案:3 悬赏:80
解决时间 2021-03-06 03:27
- 提问者网友:朱砂泪
- 2021-03-05 12:42
是两个GO中之间的部分算是批处理 还是一个GO之前的算是批处理
最佳答案
- 二级知识专家网友:浪者不回头
- 2021-03-05 13:16
GO
向 SQL Server 实用工具发出一批 Transact-SQL 语句结束的信号。
例子1:
USE AdventureWorks;
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 应用程序可以将多个 Transact-SQL 语句作为一个批发送到 SQL Server 的实例来执行。然后,该批中的语句被编译成一个执行计划。程序员在 SQL Server 实用工具中执行特殊语句,或生成 Transact-SQL 语句的脚本在 SQL Server 实用工具中运行时,使用 GO 作为批结束的信号。
例子2
USE AdventureWorks;
GO
DECLARE @NmbrContacts int
SELECT @NmbrContacts = COUNT(*)
FROM Person.Contact
PRINT 'The number of contacts as of ' +
CAST(GETDATE() AS char(20)) + ' is ' +
CAST(@NmbrContacts AS char (10))
GO
向 SQL Server 实用工具发出一批 Transact-SQL 语句结束的信号。
例子1:
USE AdventureWorks;
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 应用程序可以将多个 Transact-SQL 语句作为一个批发送到 SQL Server 的实例来执行。然后,该批中的语句被编译成一个执行计划。程序员在 SQL Server 实用工具中执行特殊语句,或生成 Transact-SQL 语句的脚本在 SQL Server 实用工具中运行时,使用 GO 作为批结束的信号。
例子2
USE AdventureWorks;
GO
DECLARE @NmbrContacts int
SELECT @NmbrContacts = COUNT(*)
FROM Person.Contact
PRINT 'The number of contacts as of ' +
CAST(GETDATE() AS char(20)) + ' is ' +
CAST(@NmbrContacts AS char (10))
GO
全部回答
- 1楼网友:我的任性你不懂
- 2021-03-05 14:47
GO 可以单独使用,作为批处理的结束。
如果是多段批处理,就是相邻两个GO 之间为一个批处理。
可以通俗理解为,如果GO之上的语句执行出错的情况下,继续向下执行。
- 2楼网友:萌萌哒小可爱
- 2021-03-05 13:51
查询分析器是sql server 2000以及之前版本使用的客户端工具,从2005开始都使用sql server management studio。
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯