“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"附近的语法不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Execute complex raw SQL query in EF6(在EF6中执行复杂的原始SQL查询)
SSIS: Model design issue causing duplications - can two fact tables be connected?(SSIS:模型设计问题导致重复-两个事实表可以连接吗?)
SQL Server Graph Database - shortest path using multiple edge types(SQL Server图形数据库-使用多种边类型的最短路径)
Invalid column name when using EF Core filtered includes(使用EF核心过滤包括时无效的列名)
How should make faster SQL Server filtering procedure with many parameters(如何让多参数的SQL Server过滤程序更快)
How can I generate an entity–relationship (ER) diagram of a database using Microsoft SQL Server Management Studio?(如何使用Microsoft SQL Server Management Studio生成数据库的实体关系(ER)图?)