SQL Server Management Studio 中“go”附近的语法不正确

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7738253/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 12:26:35  来源:igfitidea点击:

Incorrect syntax near 'go' in SQL Server Management Studio

sqlparsingnewlinessms

提问by Eldritch Conundrum

Executing the following SQL:

执行以下 SQL:

drop function f
go

in MS Sql Server Management Studio give me this parse error:

在 MS Sql Server Management Studio 中给我这个解析错误:

Msg 102, Level 15, State 1, Line 1 Incorrect syntax near 'go'.

消息 102,级别 15,状态 1,第 1 行 'go' 附近的语法不正确。

Why?

为什么?

If I open a new tab and copy/paste the SQL into it, it also fails. But If I open a new tab and retype the SQL entirely, it works fine.

如果我打开一个新选项卡并将 SQL 复制/粘贴到其中,它也会失败。但是,如果我打开一个新选项卡并完全重新键入 SQL,它就可以正常工作。

回答by DavidEG

SQL Server Management Studio can't handle some non printable characters.

SQL Server Management Studio 无法处理某些不可打印的字符。

Check the newline characters, probably you have Linux (LF) or Mac style (CR) instead of Windows style (CR and LF). You can check with any advanced text editor, for example Notepad++·

检查换行符,可能您使用的是 Linux (LF) 或 Mac 风格 (CR) 而不是 Windows 风格(CR 和 LF)。您可以使用任何高级文本编辑器进行检查,例如Notepad++·

回答by Eldritch Conundrum

You opened a file in Mac format, with Carriage Returns ('\r') newlines.

您以 Mac 格式打开了一个文件,并带有回车符 ('\r') 换行符。

The SQL parser behaves inconsistently on CR newlines. It supports them for some queries, like "select 1 go", but fails on others, like "drop function f go".

SQL 解析器在 CR 换行符上的行为不一致。它支持某些查询,例如“select 1 go”,但在其他查询中失败,例如“drop function f go”。

Convert all your sql files to windows encoding.

将所有 sql 文件转换为 windows 编码。

回答by sympatric greg

Been suffering with this problem mightily. Finally, used Notepad++.

一直深受这个问题的困扰。最后,使用 Notepad++。

Fixed by:

修正者:

Format>Convert to UNIX

格式>转换为 UNIX

followed by

其次是

Format>Convert to Windows

格式>转换为 Windows

回答by Matrix Gansburg

You should remove all the "GO" from the script and it will resolve the issue.

您应该从脚本中删除所有“GO”,它将解决问题。

Check this out for more info:

查看此了解更多信息:

https://agilewebhosting.com/knowledgebase/63/SQL-Error-Incorrect-syntax-near-andsharp039GOandsharp039.html

https://agilewebhosting.com/knowledgebase/63/SQL-Error-Incorrect-syntax-near-andsharp039GOandsharp039.html

Matrix

矩阵