I’m dying to get client software to access my SQL Server from my Mac. All this time I use Navicat for SQL Server Lite, as name, a lite/free version, which has been very outdated. The full version is more up-to-date and more features, but honestly it is a bit expensive for me.
Another option is using SQuirrel SQL which happens to have SQL Server support. Since it’s developed in Java and as long as you have JDBC driver of DBMS to access, I think it can access that DBMS well. It’s a great piece of free software. Just sometime it’s a bit complex for simple query operation that I want, for example.
Browsing around, I found this awesome project: SQL-CLI, a cross platform CLI for SQL Server. It’s developed in Node.js, so ideally if you can install Node.js in your machine in any OSes, you can install this tool, hence cross platform.
Let’s play around with it. Before we start, I don’t need to remind you that you need Node.js installed and run well in your machine. SQL-CLI doesn’t specify specific Node.js version so latest version will be good. I’m using Mac machine and Node.js v0.10.25.
Installation is as simple as opening Terminal in your OSX and type this command:
1 |
npm install -g sql-cli |
After 1 or so minutes (depends on internet connection), it will be installed globally, meaning you can execute it anywhere from Terminal.
Connect
1 |
mssql -s <YourServerNameOrIP> -u <theusername> -p <thepassword> |
Make sure to change: server name, username and password with your own. You’ll get:
1 2 3 4 5 |
Connecting to YourServerNameOrIP...done sql-cli version 0.0.9 Enter ".help" for usage hints. mssql> |
On
1 |
mssql> |
prompt, you can type commands or directly SQL Server’s T-SQL.
Let’s try by querying databases list accessible by current user:
1 2 3 4 5 6 7 8 9 10 |
mssql> .databases name ------------ master tempdb model msdb Movreak 5 row(s) returned in 166 ms |
Neat! Now, try to use one database, and show tables list:
1 2 3 4 5 6 7 8 9 |
mssql> use movreak OK mssql> .tables TABLE_CATALOG TABLE_SCHEMA TABLE_NAME TABLE_TYPE ------------- ------------ ------------------------------ ---------- Movreak dbo Movie BASE TABLE Movreak dbo MovieCast BASE TABLE 2 row(s) returned in 50 ms |
Awesome!
Last, let’s try to type a T-SQL query:
1 2 3 4 5 6 7 8 9 10 |
mssql> select top 5 movieid, title from movie order by lastmodifieddate desc movieid title ------- -------------------------- 11832 Transcendence 45522 TRANSCENDENCE (IMAX 2D) 46575 Transcendence (IMAX) 44879 BRICK MANSIONS 9828 X-Men: Days of Future Past 5 row(s) returned in 97 ms |
When in doubt, always type:
1 2 3 4 5 6 7 8 |
mssql> .help command description ------------- --------------------------- .help Shows this message .tables Lists all the tables .schema TABLE Shows the schema of a table .databases Lists all the databases .quit Exit the cli |
To quit, well just type:
1 |
mssql> .quit |
Last but certainly not least, if you have Azure CLI installed, you can integrate SQL-CLI that allows you to connect directly to SQL Server database of your Mobile Services account. To do that, just type:
1 |
azure mobile sqldb connect <mobileservicename> <username> <password> |
That’s it, enjoy!