If I remember correctly, last time Microsoft Sqlcmd require each command to end with ';' and hit Enter key to execute the command.

However, currently, we need to type the GO each time to execute the command.

So, are there other alternative such that when we hit Enter key after ending the command with ';', it will Execute the command?

  • 2
    Hitting Enter after ; is mysql interactive query tool. – Remus Rusanu Aug 28 '12 at 11:10
  • 1
    @RemusRusanu: actually nearly all query tools do it that way (Oracle, Postgres, Firebird, HSQLDB, ...). – a_horse_with_no_name Aug 28 '12 at 13:32
  • (Just a guess.) The semicolon is a statement delimiter in T-SQL. Previously it was completely optional because it was impossible to write an ambiguously interpreted batch (aka multi-statement query) that had no statement delimiters. Based on that, the semicolon was probably chosen as a batch delimiter in sqlcmd. However, since SQL Server 2005, new features have begun to appear in T-SQL that enable you to write an ambiguous batch if you don't delimit the statements. So, to avoid the ambiguity interpreting the function of ;, the need for a distinct batch delimiter must have arisen. – Andriy M Aug 28 '12 at 21:45

No, you need to type a batch separator. The default is GO. However, you can change that by using the -c switch.

For example:

C:\>sqlcmd -SServername -cFOO

1> select @@version

hit enter

2> FOO

hit enter

This will run.

Can't get rid of the intermediate enter for you. Sorry.


As for workaround, it's possible to run queries via sqlcmd command in shell, e.g.

sqlcmd -Q 'SELECT 1'
sqlcmd -Q 'SELECT 2'

without typing GO each time.

For the convenience, in order to not type credentials each time, use an alias, e.g.

alias sqlcmd="sqlcmd -S hostname -U user -P pass -d db"

Here is another version of the shell alias:

alias RUN="sqlcmd -S hostname -U user -P pass -d db -Q"

Then just run:


GO is the batch terminator. Without it sqlcmd doesn't know to send the batch to the server for execution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.