Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 370
Eldritch Conundrum Avatar asked Oct 12 '11 09:10

Eldritch Conundrum


People also ask

What is incorrect syntax near in SQL?

When executing a query in SQL and the editor throws back this error: Incorrect syntax near …'' That typically means you have used the wrong syntax for the query. This happens mostly when someone switched from one relational database to another relational database, from MySQL to MS SQL Server for example.

What is the go in SQL Server?

GO is not a Transact-SQL statement; it is a command recognized by the sqlcmd and osql utilities and SQL Server Management Studio Code editor. SQL Server utilities interpret GO as a signal that they should send the current batch of Transact-SQL statements to an instance of SQL Server.

Is Go necessary in SQL?

They're not strictly required - they're just instructions for the SQL Server Management Studio to execute the statements up to this point now and then keep on going. GO is not a T-SQL keyword or anything - it's just an instruction that works in SSMS.


1 Answers

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

like image 111
DavidEG Avatar answered Sep 20 '22 13:09

DavidEG