gpt4 book ai didi

sql - 我是否必须写入 "GO"字才能执行 SQL Server 语句?

转载 作者:行者123 更新时间:2023-12-03 01:57:35 25 4
gpt4 key购买 nike

我对 TSQL 和 SQL Server 几乎没有经验 - 所以在 MySQL 中,当我想执行一条语句时,我只需编写:

Select * from users

...然后按 Enter 键。

但是现在我看到很多 SQL Server 教程,每个语句后面都紧接着有 GO 一词。我必须写这个吗?例如:

Select * from users; GO

或者我可以简单地写:

Select * from users; <enter key pressed...>

最佳答案

在 SQL Server 中,go 分隔查询批处理。在大多数情况下它是可选的。

在 SQL Server 的早期版本中,您必须在更改表后执行 go,例如:

alter table MyTable add MyColumn int
go
select MyColumn from MyTable

如果不这样做,SQL Server 将解析查询批处理,并提示 MyColumn 不存在。请参阅MSDN :

SQL Server utilities interpret GO as a signal that they should send the current batch of Transact-SQL statements to an instance of 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 - 我是否必须写入 "GO"字才能执行 SQL Server 语句?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5450672/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com