Incorrect syntax near #39;GO#39;(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' 附近的语法不正确
基础教程推荐
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
- 是否可以执行按位分组功能? 2021-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- 在 SQL 中连接多个表 2021-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- 无法解决整理冲突 2021-01-01
