Posts

Showing posts with the label SqlCmd

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

Image
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...

SQL Server, How to execute T-SQL commands from the command line (attention this post may contain easy but useful tips 😏 )

Image
Hello friends, You know, i love “ useful but fast & easy ” tips! The question of today: Have you ever needed to run T-SQL commands from the command line? Yes? So, How to do it? Well, an easy way is to use the sqlcmd command. But what is the SqlCmd? The SqlCmd is a command line utility that is part of the standard installation of SQL Server and that you can run from the command prompt. First you need to prepare a script that contains the T-SQL commands to execute. In my example i saved myscript.sql in C:\TEMP folder. Second , just open the command prompt   And type in: sqlcmd -U "XX" -P "YYYY" -S "ZZZZ" -i “c:\temp\MyScript.sql”   You need to specifiy only the login information using: -U username -P password -S the server name -i the location of your script           Et voilà!  That's all for today! Luca Previous post: SQL Server, How to Read a list of files in a folder and compare its name with the value stored into a column...