Are there any way to stop typing 'go' in sqlcmd?
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:
RUN 'SELECT 1'