- SQL Server on Linux
- Jasmin Azemovi?
- 375字
- 2021-07-02 20:24:21
sqlcmd
The command-line utility, sqlcmd, offers batch execution of T-SQL scripts and a simple utility for executing T-SQL statements. It will be our primary interaction interface with SQL Server database engine. If you want to connect to your SQL Server instance you will need to type sqlcmd and the following parameters: (-S server name, -U user name -P password) in your bash command line.
To connect on SQL Server, type the following command:
# sqlcmd -S sqlserver -U sa
In my case, the hostname is sqlserver; instead, you can type your IP address or localhost. After you press Enter, sqlcmd will ask you to provide a valid password for the sa account:
# Password:
If login credentials are OK, you will get a screen output as follows:

Now, let's type your first SQL statement to check version number of your SQL Server database engine. As you can see in Figure 3-3, sqlcmd is numbering code lines, starting from 1. So, each time you press Enter, you will jump to the next line 2, 3, and so on. But when you need to execute your command (Enter is not enough), you will need to finish your statement with batch directive GO. Take a look at the following listing:
1> SELECT @@VERSION 2> GO --------------------------------------------------------- Microsoft SQL Server vNext (CTP1.3) - 14.0.304.138 (X64) Feb 13 2017 16:49:12 Copyright (C) 2016 Microsoft Corporation. All rights reserved. on Linux (openSUSE Leap 42.2 (1 rows affected)
First, we typed SELECT @@VERSION. After you press Enter, in the next line you need to type batch directive GO. Output (or result of execution) is an information message about SQL Server database engine and operating system version. Congratulations, you just finished your first SQL statement on a freshly installed SQL Server on Linux. It was not so hard. To exit in the bash command line, just type EXIT and press Enter. We will come back to sqlcmd in Chapter 4, Database in the Sandbox.
- 流量的秘密:Google Analytics網(wǎng)站分析與優(yōu)化技巧(第2版)
- 精通Nginx(第2版)
- Mastering Visual Studio 2017
- JavaScript全程指南
- Git Version Control Cookbook
- 零基礎(chǔ)PHP學(xué)習(xí)筆記
- Drupal 8 Blueprints
- 自己動手實(shí)現(xiàn)Lua:虛擬機(jī)、編譯器和標(biāo)準(zhǔn)庫
- Docker進(jìn)階與實(shí)戰(zhàn)
- Java程序設(shè)計與計算思維
- 你必須知道的204個Visual C++開發(fā)問題
- 微信小程序開發(fā)解析
- BIM概論及Revit精講
- Java程序設(shè)計入門
- Spring 5 Design Patterns