“GO"附近的语法不正确

Incorrect syntax near #39;GO#39;(“GO附近的语法不正确)

本文介绍了“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.

这篇关于“GO"附近的语法不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:“GO"附近的语法不正确