You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/tools/sqlcmd-utility.md
+28-26Lines changed: 28 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
2
title: "sqlcmd Utility | Microsoft Docs"
3
3
ms.custom: ""
4
-
ms.date: "07/27/2017"
4
+
ms.date: "09/12/2018"
5
5
ms.prod: sql
6
6
ms.prod_service: "sql-tools"
7
7
ms.component: "sqlcmd"
@@ -122,7 +122,7 @@ sqlcmd
122
122
## Command-line Options
123
123
**Login-Related Options**
124
124
**-A**
125
-
Signs in to SQL Server with a Dedicated Administrator Connection (DAC). This kind of connection is used to troubleshoot a server. This connection works only with server computers that support DAC. If DAC is not available, **sqlcmd** generates an error message, and then exits. For more information about DAC, see [Diagnostic Connection for Database Administrators](../database-engine/configure-windows/diagnostic-connection-for-database-administrators.md). The -A option is not supported with the -G option. When connecting to SQL Database using -A, you must be a SQL server administrator. The DAC is not availble for an Azure Active Directory adminstrator.
125
+
Signs in to SQL Server with a Dedicated Administrator Connection (DAC). This kind of connection is used to troubleshoot a server. This connection works only with server computers that support DAC. If DAC is not available, **sqlcmd** generates an error message, and then exits. For more information about DAC, see [Diagnostic Connection for Database Administrators](../database-engine/configure-windows/diagnostic-connection-for-database-administrators.md). The -A option is not supported with the -G option. When connecting to SQL Database using -A, you must be a SQL server administrator. The DAC is not available for an Azure Active Directory administrator.
126
126
127
127
**-C**
128
128
This switch is used by the client to configure it to implicitly trust the server certificate without validation. This option is equivalent to the ADO.NET option `TRUSTSERVERCERTIFICATE = true`.
@@ -134,7 +134,7 @@ sqlcmd
134
134
Specifies the number of seconds before a **sqlcmd** login to the ODBC driver times out when you try to connect to a server. This option sets the **sqlcmd** scripting variable SQLCMDLOGINTIMEOUT. The default time-out for login to **sqlcmd** is eight seconds. When using the **-G** option to connect to SQL Database or SQL Data Warehouse and authenticate using Azure Active Directory, a timeout value of at least 30 seconds is recommended. The login time-out must be a number between 0 and 65534. If the value supplied is not numeric or does not fall into that range, **sqlcmd** generates an error message. A value of 0 specifies time-out to be infinite.
135
135
136
136
**-E**
137
-
Uses a trusted connection instead of using a user name and password to log on to SQL Server. By default, without **-E** specified, **sqlcmd** uses the trusted connection option.
137
+
Uses a trusted connection instead of using a user name and password to sign in to SQL Server. By default, without **-E** specified, **sqlcmd** uses the trusted connection option.
138
138
139
139
The **-E** option ignores possible user name and password environment variable settings such as SQLCMDPASSWORD. If the **-E** option is used together with the **-U** option or the **-P** option, an error message is generated.
140
140
@@ -145,7 +145,8 @@ Sets the Column Encryption Setting to `Enabled`. For more information, see [Alwa
145
145
This switch is used by the client when connecting to SQL Database or SQL Data Warehouse to specify that the user be authenticated using Azure Active Directory authentication. This option sets the **sqlcmd** scripting variable SQLCMDUSEAAD = true. The -G switch requires at least **sqlcmd** version [13.1](http://go.microsoft.com/fwlink/?LinkID=825643). To determine your version, execute `sqlcmd -?`. For more information, see [Connecting to SQL Database or SQL Data Warehouse By Using Azure Active Directory Authentication](https://azure.microsoft.com/documentation/articles/sql-database-aad-authentication/). The -A option is not supported with the -G option.
146
146
147
147
> [!IMPORTANT]
148
-
> The **-G** option only applies to Azure SQL Database and Azure Data Warehouse.
148
+
> The **-G** option only applies to Azure SQL Database and Azure Data Warehouse.
149
+
> AAD Integrated Authentication is not currently supported on Linux or macOS.
149
150
150
151
-**Azure Active Directory Username and Password:**
151
152
@@ -162,7 +163,8 @@ Sets the Column Encryption Setting to `Enabled`. For more information, see [Alwa
162
163
163
164
- **Azure Active Directory Integrated**
164
165
165
-
For Azure Active Directory Integrated authentication, provide the **-G** option without a user name or password:
166
+
For Azure Active Directory Integrated authentication, provide the **-G** option without a user name or password.
167
+
*AAD Integrated Authentication is not currently supported on Linux or macOS*.
@@ -245,7 +247,7 @@ We recommend that you use a strong password.
245
247
246
248
If neither the **-U** option nor the **-P** option is specified, **sqlcmd** tries to connect by using Microsoft Windows Authentication mode. Authentication is based on the Windows account of the user who is running **sqlcmd**.
247
249
248
-
If the **-U** option is used with the **-E** option (described later in this topic), an error message is generated. If the **–U** option is followed by more than one argument, an error message is generated and the program exits.
250
+
If the **-U** option is used with the **-E** option (described later in this article), an error message is generated. If the **–U** option is followed by more than one argument, an error message is generated and the program exits.
249
251
250
252
**-z** *new_password*
251
253
Change password:
@@ -330,7 +332,7 @@ We recommend that you use a strong password.
330
332
> [!IMPORTANT]
331
333
> Do not use the GO terminator in the query.
332
334
333
-
If **-b** is specified together with this option, **sqlcmd** exits on error. **-b** is described later in this topic.
335
+
If **-b** is specified together with this option, **sqlcmd** exits on error. **-b** is described later in this article.
334
336
335
337
**-Q"** *cmdline query* **"**
336
338
Executes a query when **sqlcmd** starts and then immediately exits **sqlcmd**. Multiple-semicolon-delimited queries can be executed.
@@ -346,7 +348,7 @@ We recommend that you use a strong password.
346
348
> [!IMPORTANT]
347
349
> Do not use the GO terminator in the query.
348
350
349
-
If **-b** is specified together with this option, **sqlcmd** exits on error. **-b** is described later in this topic.
351
+
If **-b** is specified together with this option, **sqlcmd** exits on error. **-b** is described later in this article.
350
352
351
353
**-t** *query_timeout*
352
354
Specifies the number of seconds before a command (or SQL statement) times out. This option sets the **sqlcmd** scripting variable SQLCMDSTATTIMEOUT. If a *time_out* value is not specified, the command does not time out. The *query**time_out* must be a number between 1 and 65534. If the value supplied is not numeric or does not fall into that range, **sqlcmd** generates an error message.
@@ -366,7 +368,7 @@ We recommend that you use a strong password.
366
368
367
369
**Formatting Options**
368
370
**-h** *headers*
369
-
Specifies the number of rows to print between the column headings. The default is to print headings one time for each set of query results. This option sets the **sqlcmd** scripting variable SQLCMDHEADERS. Use **-1** to specify that headers must not be printed. Any value that is not valid causes **sqlcmd** to generate an error message and then exit.
371
+
Specifies the number of rows to print between the column headings. The default is to print headings one time for each set of query results. This option sets the **sqlcmd** scripting variable SQLCMDHEADERS. Use **-1** to specify that headers should not be printed. Any value that is not valid causes **sqlcmd** to generate an error message and then exit.
370
372
371
373
**-k** [**1** | **2**]
372
374
Removes all control characters, such as tabs and new line characters from the output. This parameter preserves column formatting when data is returned. If 1 is specified, the control characters are replaced by a single space. If 2 is specified, consecutive control characters are replaced by a single space. **-k** is the same as **-k1**.
@@ -461,7 +463,7 @@ We recommend that you use a strong password.
461
463
462
464
Where:
463
465
464
-
`x` = Number of transactions that are processed by SQL Server.
466
+
`x` = Number of transactions that are processed by SQL Server.
465
467
466
468
`t1` = Total time for all transactions.
467
469
@@ -492,7 +494,7 @@ We recommend that you use a strong password.
492
494
493
495
When multiple results are returned, **sqlcmd** prints a blank line between each result set in a batch. In addition, the `<x> rows affected` message does not appear when it does not apply to the statement executed.
494
496
495
-
To use **sqlcmd** interactively, type **sqlcmd** at the command prompt with any one or more of the options described earlier in this topic. For more information, see [Use the sqlcmd Utility](~/relational-databases/scripting/sqlcmd-use-the-utility.md)
497
+
To use **sqlcmd** interactively, type **sqlcmd** at the command prompt with any one or more of the options described earlier in this article. For more information, see [Use the sqlcmd Utility](~/relational-databases/scripting/sqlcmd-use-the-utility.md)
496
498
497
499
> [!NOTE]
498
500
> The options **-L**, **-Q**, **-Z** or **-i** cause **sqlcmd** to exit after execution.
@@ -536,7 +538,7 @@ We recommend that you use a strong password.
536
538
|SQLCMDINI||R|""|
537
539
|SQLCMDUSEAAD | -G | R/W | "" |
538
540
539
-
SQLCMDUSER, SQLCMDPASSWORD and SQLCMDSERVER are set when **:Connect** is used.
541
+
SQLCMDUSER, SQLCMDPASSWORD, and SQLCMDSERVER are set when **:Connect** is used.
540
542
541
543
R indicates the value can only be set one time during program initialization.
542
544
@@ -562,7 +564,7 @@ We recommend that you use a strong password.
562
564
- All **sqlcmd** commands, except GO, must be prefixed by a colon (:).
563
565
564
566
> [!IMPORTANT]
565
-
> To maintain backward compatibility with existing **osql** scripts, some of the commands will be recognized without the colon. This is indicated by the [**:**].
567
+
> To maintain backward compatibility with existing **osql** scripts, some of the commands will be recognized without the colon, indicated by the [**:**].
566
568
567
569
- **sqlcmd** commands are recognized only if they appear at the start of a line.
568
570
@@ -632,18 +634,18 @@ We recommend that you use a strong password.
632
634
Switches error output to the **stdout** stream. If this has been redirected, the target to which the stream has been redirected will receive the error output.
Creates and redirects all query results to the file specified by *file name*, to **stderr** or to **stdout**. By default, output is sent to **stdout**. If the file already exists, it will be truncated to zero bytes. The **Out** command can appear multiple times in a script.
637
+
Creates and redirects all query results to the file specified by *file name*, to **stderr** or to **stdout**. By default, output is sent to **stdout**. If the file already exists, it is truncated to zero bytes. The **Out** command can appear multiple times in a script.
Creates and redirects all performance trace information to the file specified by *file name*, to **stderr** or to **stdout**. By default performance trace output is sent to **stdout**. If the file already exists, it will be truncated to zero bytes. The **Perftrace** command can appear multiple times in a script.
640
+
Creates and redirects all performance trace information to the file specified by *file name*, to **stderr** or to **stdout**. By default performance trace output is sent to **stdout**. If the file already exists, it is truncated to zero bytes. The **Perftrace** command can appear multiple times in a script.
639
641
640
642
**Execution Control Commands**
641
643
**:On Error**[ **exit** | **ignore**]
642
644
Sets the action to be performed when an error occurs during script or batch execution.
643
645
644
646
When the **exit** option is used, **sqlcmd** exits with the appropriate error value.
645
647
646
-
When the **ignore** option is used, **sqlcmd** ignores the error and continues executing the batch or script. By default, an error message will be printed.
648
+
When the **ignore** option is used, **sqlcmd** ignores the error and continues executing the batch or script. By default, an error message is printed.
647
649
648
650
[**:**] **QUIT**
649
651
Causes **sqlcmd** to exit.
@@ -727,7 +729,7 @@ We recommend that you use a strong password.
727
729
728
730
If *timeout* is not specified, the value of the SQLCMDLOGINTIMEOUT variable is the default.
729
731
730
-
If only *user_name* is specified (either as an option, or as an environment variable), the user will be prompted to enter a password. This is not true if the SQLCMDUSER or SQLCMDPASSWORD environment variables have been set. If neither options nor environment variables are provided, Windows Authentication mode is used to sign in. For example to connect to an instance, `instance1`, of SQL Server, `myserver`, by using integrated security you would use the following:
732
+
If only *user_name* is specified (either as an option, or as an environment variable), the user will be prompted to enter a password. Users are not prompted if the SQLCMDUSER or SQLCMDPASSWORD environment variables have been set. If neither options nor environment variables are provided, Windows Authentication mode is used to sign in. For example to connect to an instance, `instance1`, of SQL Server, `myserver`, by using integrated security you would use the following command:
731
733
732
734
`:connect myserver\instance1`
733
735
@@ -748,7 +750,7 @@ We recommend that you use a strong password.
748
750
> The command is executed on the computer on which **sqlcmd** is running.
749
751
750
752
**:XML** [**ON** | **OFF**]
751
-
For more information, see [XML Output Format](#OutputXML) and [JSON Output Format](#OutputJSON) in this topic
753
+
For more information, see [XML Output Format](#OutputXML) and [JSON Output Format](#OutputJSON) in this article
752
754
753
755
**:Help**
754
756
Lists **sqlcmd** commands together with a short description of each command.
@@ -758,7 +760,7 @@ We recommend that you use a strong password.
758
760
759
761
- **:Error**, **:Out** and **:Perftrace** should use separate **\<***filename***>**. If the same **\<***filename***>** is used, inputs from the commands may be intermixed.
760
762
761
-
- If an input file that is located on a remote server is called from **sqlcmd** on a local computer and the file contains a drive file path such as :out c:\OutputFile.txt. The output file will be created on the local computer and not on the remote server.
763
+
- If an input file that is located on a remote server is called from **sqlcmd** on a local computer and the file contains a drive file path such as :Out c:\OutputFile.txt. The output file is created on the local computer and not on the remote server.
762
764
763
765
- Valid file paths include: `C:\<filename>`, `\\<Server>\<Share$>\<filename>` and `"C:\Some Folder\<file name>"`. If there is a space in the path, use quotation marks.
764
766
@@ -768,7 +770,7 @@ We recommend that you use a strong password.
768
770
769
771
**sqlcmd** prints any informational message that is sent by the server. In the following example, after the Transact-SQL statements are executed, an informational message is printed.
770
772
771
-
At the command prompt, type the following:
773
+
At the command prompt, type the command:
772
774
773
775
`sqlcmd`
774
776
@@ -785,7 +787,7 @@ When you press ENTER, the following informational message is printed: "Changed d
785
787
786
788
This line will be followed by a separator line that is a series of dash characters. The following output shows an example.
787
789
788
-
Start **sqlcmd**. At the **sqlcmd** command prompt, type the following:
790
+
Start **sqlcmd**. At the **sqlcmd** command prompt, type the query:
789
791
790
792
`USE AdventureWorks2012;`
791
793
@@ -807,7 +809,7 @@ When you press ENTER, the following informational message is printed: "Changed d
807
809
808
810
`(2 row(s) affected)`
809
811
810
-
Although the `BusinessEntityID` column is only 4 characters wide, it has been expanded to accommodate the longer column name. By default, output is terminated at 80 characters. This can be changed by using the **-w** option, or by setting the SQLCMDCOLWIDTH scripting variable.
812
+
Although the `BusinessEntityID` column is only four characters wide, it has been expanded to accommodate the longer column name. By default, output is terminated at 80 characters. This can be changed by using the **-w** option, or by setting the SQLCMDCOLWIDTH scripting variable.
811
813
812
814
### <a name="OutputXML"></a> XML Output Format
813
815
XML output that is the result of a FOR XML clause is output, unformatted, in a continuous stream.
@@ -817,21 +819,21 @@ When you press ENTER, the following informational message is printed: "Changed d
817
819
> [!NOTE]
818
820
> **sqlcmd** returns error messages in the usual format. Notice that the error messages are also output in the XML text stream in XML format. By using `:XML ON`, **sqlcmd** does not display informational messages.
819
821
820
-
To set the XML mode off, use the following command: `:XML OFF`.
822
+
To set the XML mode to off, use the following command: `:XML OFF`.
821
823
822
824
The GO command should not appear before the XML OFF command is issued because the XML OFF command switches **sqlcmd** back to row-oriented output.
823
825
824
-
XML (streamed) data and rowset data cannot be mixed. If the XML ON command has not been issued before a Transact-SQL statement that outputs XML streams is executed, the output will be garbled. If the XML ON command has been issued, you cannot execute Transact-SQL statements that output regular row sets.
826
+
XML (streamed) data and rowset data can't be mixed. If the XML ON command hasn't been issued before a Transact-SQL statement that outputs XML streams is executed, the output is garbled. Once the XML ON command has been issued, you can't execute Transact-SQL statements that output regular row sets.
825
827
826
828
> [!NOTE]
827
829
> The **:XML** command does not support the SET STATISTICS XML statement.
828
830
829
831
### <a name="OutputJSON"></a> JSON Output Format
830
832
When you expect JSON output, use the following command: `:XML ON`. Otherwise the output includes both the column name and the JSON text. This output is not valid JSON.
831
833
832
-
To set the XML mode off, use the following command: `:XML OFF`.
834
+
To set the XML mode to off, use the following command: `:XML OFF`.
833
835
834
-
For more info, see [XML Output Format](#OutputXML) in this topic.
836
+
For more info, see [XML Output Format](#OutputXML) in this article.
835
837
836
838
### Using Azure Active Directory Authentication
837
839
Examples using Azure Active Directory Authentication:
0 commit comments