|
| 1 | +[SQLCMD](https://docs.microsoft.com/sql/linux/sql-server-linux-connect-and-query-sqlcmd){:target="_blank"} is a command line tool that enables you to connect to SQL Server and run queries. |
| 2 | + |
| 3 | +```terminal |
| 4 | +sudo su |
| 5 | +
|
| 6 | +#Download appropriate package for the OS version |
| 7 | +#Choose only ONE of the following, corresponding to your OS version |
| 8 | +
|
| 9 | +#SUSE Linux Enterprise Server 11 SP4 |
| 10 | +#Ensure SUSE Linux Enterprise 11 Security Module has been installed |
| 11 | +zypper ar https://packages.microsoft.com/config/sles/11/prod.repo |
| 12 | +
|
| 13 | +#SUSE Linux Enterprise Server 12 |
| 14 | +zypper ar https://packages.microsoft.com/config/sles/12/prod.repo |
| 15 | +
|
| 16 | +#SUSE Linux Enterprise Server 15 |
| 17 | +zypper ar https://packages.microsoft.com/config/sles/15/prod.repo |
| 18 | +#(Only for driver 17.3 and below) |
| 19 | +SUSEConnect -p sle-module-legacy/15/x86_64 |
| 20 | +
|
| 21 | +exit |
| 22 | +sudo ACCEPT_EULA=Y zypper install msodbcsql17 |
| 23 | +# optional: for bcp and sqlcmd |
| 24 | +sudo ACCEPT_EULA=Y zypper install mssql-tools |
| 25 | +echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile |
| 26 | +echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc |
| 27 | +source ~/.bashrc |
| 28 | +# optional: for unixODBC development headers |
| 29 | +sudo zypper install unixODBC-devel |
| 30 | +``` |
| 31 | + |
| 32 | +After installing SQLCMD, you can connect to SQL Server using the following command: |
| 33 | + |
| 34 | +```terminal |
| 35 | +sqlcmd -S your_database.database.windows.net -U your_user -P your_password -d your_database |
| 36 | +1> # You're connected! Type your T-SQL statements here. Use the keyword 'GO' to execute each batch of statements. |
| 37 | +``` |
| 38 | + |
| 39 | +This how to run a basic inline query. The results will be printed to the STDOUT. |
| 40 | + |
| 41 | +```terminal |
| 42 | +sqlcmd -S your_database.database.windows.net -U your_user -P your_password -d your_database -Q "SELECT @@VERSION" |
| 43 | +``` |
| 44 | + |
| 45 | +```results |
| 46 | +------------------------------------------------------------ |
| 47 | +Microsoft SQL Azure (RTM) - 12.0.2000.8 |
| 48 | + May 15 2020 00:47:08 |
| 49 | + Copyright (C) 2019 Microsoft Corporation |
| 50 | + |
| 51 | +
|
| 52 | +(1 rows affected) |
| 53 | +``` |
| 54 | + |
| 55 | +> You have successfully installed SQL Server Command Line Utilities on your SLES machine! |
0 commit comments