Sql-server – How to bypass the typing of `GO` in `sqlcmd`

clientlinuxsql-server-2017

sqlcmd has this most annoying this of having to type GO after every command, how can I get around this?

SELECT 1 AS "foo"
2> GO
foo        
-----------
          1
(1 rows affected)

Can I make this like psql…

test=# SELECT 1;
 ?column? 
----------
        1
(1 row)

Best Answer

Reference: https://docs.microsoft.com/en-us/sql/tools/sqlcmd-utility

With -q you can execute multiple query, as you do not get your prompt back until you hit ctrl+c.

-q" cmdline query " Executes a query when sqlcmd starts, but does not exit sqlcmd when the query has finished running. Multiple-semicolon-delimited queries can be executed. Use quotation marks around the query, as shown in the following example.

This is in my workstation.

If you want to exit use <code>-Q</code> instead of -q.

-Q" cmdline query " Executes a query when sqlcmd starts and then immediately exits sqlcmd. Multiple-semicolon-delimited queries can be executed. Use quotation marks around the query, as shown in the following example.enter image description here