I have been scratching my head for a while with this error.
The following script:
alter table t alter column c int
GO
Results in error:
Incorrect syntax near 'GO'.
What I mainly want is to embed this script inside of a longer script hence the need to execute the transaction before the rest of the script proceeds. I have also tried it with and without semicolons and that makes no difference.
I would appreciate any kind guidance.
Same error in SQL server 2016 and 2019. I am running SQL in SSMS interactively. The existence of the table does not make a difference to the error. I have tried it with the following DDL:
create table t (c float)
screenshow with SELECT then GO showing that other statements with GO work fine.
I was able to reproduce the issue with a SQL file that uses Macintosh line endings (CR instead of CR LF or LF):
The solution is to convert the line ending to Windows as described here.