问题
Executing the following SQL:
drop function f
go
in MS Sql Server Management Studio give me this parse error:
Msg 102, Level 15, State 1, Line 1 Incorrect syntax near '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.
回答1:
SQL Server Management Studio can't handle some non printable characters.
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++·
回答2:
You opened a file in Mac format, with Carriage Returns ('\r') newlines.
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".
Convert all your sql files to windows encoding.
回答3:
Been suffering with this problem mightily. Finally, used Notepad++.
Fixed by:
Format>Convert to UNIX
followed by
Format>Convert to Windows
回答4:
You should remove all the "GO" from the script and it will resolve the issue.
Check this out for more info:
https://agilewebhosting.com/knowledgebase/63/SQL-Error-Incorrect-syntax-near-andsharp039GOandsharp039.html
Matrix
来源:https://stackoverflow.com/questions/7738253/incorrect-syntax-near-go-in-sql-server-management-studio