'GO' 附近的语法不正确
如何通过 ADO.NET 在单个命令中执行以下 SQL(单次执行)?
How can I execute the following SQL inside a single command (single execution) through ADO.NET?
ALTER TABLE [MyTable]
ADD NewCol INT
GO
UPDATE [MyTable]
SET [NewCol] = 1
不支持批处理分隔符GO
,没有它,第二条语句将失败.
The batch separator GO
is not supported, and without it the second statement fails.
除了使用多个 command
执行之外,还有其他解决方案吗?
Are there any solutions to this other than using multiple command
executions?
推荐答案
GO
关键字不是 T-SQL,而是一个 SQL Server Management Studio 工件,可以让你分离脚本的执行多批次文件.即当您在 SSMS 中运行 T-SQL 脚本文件时,语句将分批运行,由 GO
关键字分隔.可以在此处找到更多详细信息:https://msdn.microsoft.com/en-我们/图书馆/ms188037.aspx
The GO
keyword is not T-SQL, but a SQL Server Management Studio artifact that allows you to separate the execution of a script file in multiple batches.I.e. when you run a T-SQL script file in SSMS, the statements are run in batches separated by the GO
keyword. More details can be found here: https://msdn.microsoft.com/en-us/library/ms188037.aspx
如果你读到了,你会发现 sqlcmd 和 osql 也支持 GO
.
If you read that, you'll see that sqlcmd and osql do also support GO
.
SQL Server 不理解 GO
关键字.因此,如果您需要一个等价物,您需要自己分开并单独运行批次.
SQL Server doesn't understand the GO
keyword. So if you need an equivalent, you need to separate and run the batches individually on your own.
相关文章