MSSQL-CLI is a useful new command line tool. Not so new because this tool exist since 2018 but a little bit unknow.

You find this tool on GitHub here.

One of the big advantage is the number of platforms available, Windows of course but also macOS, Ubuntu, Debian, CentOs, Red Hat, OpenSuse, Suse Enterprise and Fedora.
This interactive command-line query tool has many advantages like the full IntelliSense support, the auto-complete, the syntax highlighting, the query history, the configuration file support, the Multiline queries,..

I test the tool on a Windows Server 2016.
Before you install it on Windows, you need to install the latest version of Python.
During the installation of Python, do not forget to select the ‘Add Python to PATH’ option.
After, you can install mssql-cli with the command:

Pip install mssql_cli-015.0-py2.py3-none-win32.whl

First, to see all options, you use the command:

mssql-cli --help


To begin, in my test environment, I connect to my local instance INST_SQL2019. I use the option –S for the server with the value .\INST_SQL2019 and the option –E to use the integrated authentication with my account:

Mssql-cli –S .\SQL2019RTM –E

After that, I can begin to test the tool with some commands. When I begin to write the query, the IntelliSense propose me every time something and you can see the syntax highlighting in this screenshot:

Let’s go with a first easy select:

As you can see, the result is more to read as with SQLCMD…

You have also “special Commands”
\lt can be helpful and show you all tables witch contain . \ls can be also use to show schema witch contain or \lv for views

\sn can save a with the name and after you can use \n to run the query. \dn delete the name and associated query.

You can find all special commands here,

You have also some shortcut very useful like:
Ctrl + D: exit mssql-cli
Ctrl + K: Clear the screen
F3: enable the multiline mode

As you can see, after I enable the multiline mode, you have at bottom of screen the indication.
To add line, you press Enter, see the “….” in the next line  and to execute the query you need to use the “;” as validator

I was very surprise to test and use it. This tool is much better that sqlcmd but not sure, that it is better than PowerShell in a Windows environment.
All information how to use this tool is here.
Enjoy using it! 😎