Cross platform command line interface for SQL Server
NOTE: All Pull-Requests must be made into the dev
branch.
You can install the sql-cli npm package.
npm install -g sql-cli
If you're more adventurous and like to live on the edge then you can install development version as follows:
Get Startedgit clone https://github.com/hasankhan/sql-cli
cd sql-cli
git checkout dev
npm install -g
To get the list of all parameters type 'mssql -h'
Usage: mssql [options]
Â
Options:
Â
  -h, --help                     output usage information
  -V, --version                  output the version number
  -s, --server <server>          Server to connect to
  -u, --user <user>              User name to use for authentication
  -p, --pass <pass>              Password to use for authentication
  -o, --port <port>              Port to connect to
  -t, --timeout <timeout>        Connection timeout in ms
  -d, --database <database>      Database to connect to
  -q, --query <query>            The query to execute
  -v, --tdsVersion <tdsVersion>  Version of tds protocol to use [7_4, 7_2, 7_3_A, 7_3_B, 7_4]
  -e, --encrypt                  Enable encryption
  -f, --format <format>          The format of output [table, csv, xml, json]
  -c, --config <path>            Read connection information from config file
To connect to a SQL Server instance in Azure invoke mssql as follows
mssql -s abcdef.database.windows.net -u username@abcdef -p thepassword -d mydatabase -e
You will get a prompt as follows:
Connecting to abcdef.database.windows.net...done
Â
sql-cli version 0.1.0
Enter ".help" for usage hints.
mssql>
To get the list of all commands use the '.help' command
mssql>Â .help
.help               Shows this message                             Â
.databases          Lists all the databases                        Â
.tables             Lists all the tables                           Â
.sprocs             Lists all the stored procedures                Â
.search TYPE VALUE  Searches for a value of specific type (col|text)
.indexes TABLE      Lists all the indexes of a table               Â
.read FILENAME      Execute commands in a file                     Â
.run FILENAME       Execute the file as a sql script               Â
.schema TABLE       Shows the schema of a table                    Â
.analyze            Analyzes the database for missing indexes.     Â
.quit               Exit the cli
To get the list of databases use the '.databases' command
mssql>Â .databases
name
------------------
master
test
Â
2 row(s) returned in 12 ms
To get the list of tables use the '.tables' command
mssql> use test;
OK
mssql>Â .tables
database  schema  name   type
--------Â Â ------Â Â -----Â Â ----------
test      dbo     books  BASE TABLE
test      dbo     test   BASE TABLE
Â
2 row(s) returned in 24 ms
To find all tables with a specified column name
mssql> .search col ID
Searching...
table_name                  schema_name  column_name    Â
--------------------------Â Â -----------Â Â ----------------
Customers                   dbo          ID    Â
Products                    dbo          ID
2Â row(s)Â returned
Â
Executed in 1 ms
To find all records in a database with a value
mssql> .search text john
Searching...
ColumnName                  ColumnValue   Â
--------------------------Â Â -----------
[dbo].[Customers].[Name]    John            Â
[dbo].[Books].[Author]      John       Â
2Â row(s)Â returned
Â
Executed in 1 ms
To exit the cli use the '.quit' command
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4