Search code examples
sqlparsingnewlinessms

Incorrect syntax near 'go' in SQL Server Management Studio


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.


Solution

  • 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++·