'GO'附近的语法不正确 [英] Incorrect syntax near 'GO'

查看:160
本文介绍了'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.

除了使用多个命令执行之外,还有其他解决方案吗?

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/zh- us / library / 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'附近的语法不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆