Skip to content

SQL Server Tool: MSSQL-CLI

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! 😎

Let’s work together

Ready to operate at
the next level?

Tell us about your challenge. We’ll bring the depth, the expertise, and the Swiss precision.

Stéphane Haby

Stéphane Haby

Stéphane Haby has more than 20 years of experience in Microsoft solutions, specializing in the installation, migration, best practices, and performance analysis of Microsoft SQL Server, as well as Microsoft Business Intelligence solutions (SharePoint, Office) and .NET development for the banking sector. A former Microsoft Most Valuable Professional (MVP) and early adopter of Microsoft Team System in France, he has authored several technical articles. He holds Microsoft Certified Solutions Associate (MCSA) and Expert (MCSE) for SQL Server, MCTS, MCITP for SQL Server 2008, and ITIL V3 Foundation certifications. His industry experience covers chemicals and pharma, banking, and financial services.View Author posts

182 posts since April 2011

Leave a Comment

Your email address will not be published. Required fields are marked *