SQL Server: let's install SQL Server command line tools for Linux and run the first query!

Hi Guys,


In yesterday's post we installed step by step VMware, Ubuntu 20.4 and SQL Server 2019 for linux

Since SQL Server for linux doesn't have the Management Studio (SSMS) we need to install the command line tool

Today, we will also see how to execute the first query by creating a new database and inserting some data.

Let's go!


SQL Server command line tools installation

Since curl is not installed by default you need to install it with these command:


sudo apt-get update 
sudo apt install curl 

Now enter this command:


curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -


The process must ends with an OK message. So Curl in installed.

Now type this command:


curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list


Now type these commands to download the mssql-tools:


sudo apt-get update 
sudo apt-get install mssql-tools unixodbc-dev

Press "Y"

And Accept the license terms!

Now execute these command to install the mssql-tools:


sudo apt-get update 
sudo apt-get install mssql-tools

Et volià ....mssql-tools is installed!

Just set the PATH by doing:


echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
source ~/.bashrc 

...and we are ready to connect to SQL Server:


Let's Connect!

Now we can connect using the sqlcmd

The syntax is simple, just type the command


sqlcmd -S localhost -U SA -P 'put_your_password'

if succesful the '1>' character will appear:

Good! very very good! We can connect to the SQL Server engine.


Let's run the first commands

Now, from the command line we can execute T-SQL commands.

We need to create a test database and then we need to create a table.

T-SQL command to create an empty database is really simple. just tpye the "Create Database" command followed by the name of the database:


CREATE DATABASE TEST

then type the command "GO" to proceed with the creation of the database:


GO

Now we can create a table OrdTes (...remerber to type GO after each command)


CREATE TABLE ORDTES (id int identity(1,1), Customer Varchar(20), DateDoc datetime);

Insert some data..


INSERT INTO ORDTES (Customer, DateDoc) values ('Luca','01-01-2021')

And read inserted data..


SELECT * FROM ORDTES


That's all for today but we are ready to run some benchmark just to compare SQL Server performance running in Windows and in Ubuntu (linux).

 

If I were you ... I would be curious so ... STAY TUNED mates!







Next post:

Previous post: SQL Server: Step by Step ... from 0 to SQL Server 2019 for Linux

Comments

I Post più popolari

SQL Server, execution plan and the lazy spool (clearly explained)

SQL Server, datetime vs. datetime2

La clausola NOLOCK. Approfondiamo e facciamo chiarezza!