This post is authored by Alan Yu, Program Manager, SQL Server.
mssql-cli is a new and interactive command line query tool for SQL Server. This open source tool works cross-platform and is part of the dbcli community.
Feature highlight: Special commands
In our initial release, mssql-cli brought auto-completion, syntax highlighting, configuration support, and history to your SQL Server command line experience. With v0.10.0, we introduce special commands.
Special commands are meant to make your life easier. They are shortcuts to perform common tasks and queries. All special commands start with a backslash (), and you can use the built-in IntelliSense to see a list of special commands you can use. You can also learn more by running the following command:
To start off, let’s say you have a common query you run often, but don’t want to type it out each time or scroll through your history. You can “save” your query by running the following special command:
$ mssql-cli>sn address select * from "Person"."AddressType"
To execute this query, simply run:
$ mssql-cli>n address
To see this in action, see the gif below:
To learn more about special commands, please check out usage guide, which also includes information about other features that you can use with mssql-cli.
In order to install mssql-cli, you must have Python on your machine. Please refer to the installation guide for OS-specific methods to get Python.
mssql-cli is installed via pip. If you know pip, you can install mssql-cli using command.
$ pip install mssql-cli
If you are having installation issues or would like more specific instructions, please see the installation guide.
Once you have mssql-cli installed, connect to your database with the command:
$ mssql-cli -S <server name> -U <user name> -d <database name>
Source: Microsoft Blog – SQL Server News – Announcing a new update for mssql-cli: Special Commands