Skip to content

Commit d9ee771

Browse files
authored
Merge pull request MicrosoftDocs#7211 from VanMSFT/20180912_changeSqlcmd
Added new AAD auth verbiage and fixed acrolinks 1340732
2 parents 113b90d + d472f35 commit d9ee771

File tree

1 file changed

+30
-28
lines changed

1 file changed

+30
-28
lines changed

docs/tools/sqlcmd-utility.md

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "sqlcmd Utility | Microsoft Docs"
33
ms.custom: ""
4-
ms.date: "07/27/2017"
4+
ms.date: "09/12/2018"
55
ms.prod: sql
66
ms.prod_service: "sql-tools"
77
ms.component: "sqlcmd"
@@ -122,7 +122,7 @@ sqlcmd
122122
## Command-line Options
123123
**Login-Related Options**
124124
**-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.
126126

127127
**-C**
128128
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
134134
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.
135135

136136
**-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.
138138

139139
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.
140140

@@ -145,7 +145,8 @@ Sets the Column Encryption Setting to `Enabled`. For more information, see [Alwa
145145
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.
146146

147147
> [!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.
149150
150151
- **Azure Active Directory Username and Password:**
151152

@@ -162,7 +163,8 @@ Sets the Column Encryption Setting to `Enabled`. For more information, see [Alwa
162163
163164
- **Azure Active Directory Integrated**
164165
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*.
166168
167169
```
168170
Sqlcmd -S Target_DB_or_DW.testsrv.database.windows.net -G
@@ -245,7 +247,7 @@ We recommend that you use a strong password.
245247
246248
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**.
247249
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.
249251
250252
**-z** *new_password*
251253
Change password:
@@ -318,7 +320,7 @@ We recommend that you use a strong password.
318320
**-I**
319321
Sets the SET QUOTED_IDENTIFIER connection option to ON. By default, it is set to OFF. For more information, see [SET QUOTED_IDENTIFIER (Transact-SQL)](~/t-sql/statements/set-quoted-identifier-transact-sql.md).
320322
321-
**-q"** *cmdline query* **"**
323+
**-q "** *cmdline query* **"**
322324
Executes a query when **sqlcmd** starts, but does not exit **sqlcmd** when the query has finished running. Multiple-semicolon-delimited queries can be executed. Use quotation marks around the query, as shown in the following example.
323325
324326
At the command prompt, type:
@@ -330,9 +332,9 @@ We recommend that you use a strong password.
330332
> [!IMPORTANT]
331333
> Do not use the GO terminator in the query.
332334
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.
334336
335-
**-Q"** *cmdline query* **"**
337+
**-Q "** *cmdline query* **"**
336338
Executes a query when **sqlcmd** starts and then immediately exits **sqlcmd**. Multiple-semicolon-delimited queries can be executed.
337339
338340
Use quotation marks around the query, as shown in the following example.
@@ -346,7 +348,7 @@ We recommend that you use a strong password.
346348
> [!IMPORTANT]
347349
> Do not use the GO terminator in the query.
348350
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.
350352
351353
**-t** *query_timeout*
352354
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.
366368
367369
**Formatting Options**
368370
**-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.
370372
371373
**-k** [**1** | **2**]
372374
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.
461463
462464
Where:
463465
464-
`x` = Number of transactions that are processed by SQL Server .
466+
`x` = Number of transactions that are processed by SQL Server.
465467
466468
`t1` = Total time for all transactions.
467469
@@ -492,7 +494,7 @@ We recommend that you use a strong password.
492494
493495
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.
494496
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)
496498
497499
> [!NOTE]
498500
> 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.
536538
|SQLCMDINI||R|""|
537539
|SQLCMDUSEAAD | -G | R/W | "" |
538540
539-
SQLCMDUSER, SQLCMDPASSWORD and SQLCMDSERVER are set when **:Connect** is used.
541+
SQLCMDUSER, SQLCMDPASSWORD, and SQLCMDSERVER are set when **:Connect** is used.
540542
541543
R indicates the value can only be set one time during program initialization.
542544
@@ -562,7 +564,7 @@ We recommend that you use a strong password.
562564
- All **sqlcmd** commands, except GO, must be prefixed by a colon (:).
563565
564566
> [!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 [**:**].
566568
567569
- **sqlcmd** commands are recognized only if they appear at the start of a line.
568570
@@ -632,18 +634,18 @@ We recommend that you use a strong password.
632634
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.
633635
634636
**:Out \<** *filename* **>**| **STDERR**| **STDOUT**
635-
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.
636638
637639
**:Perftrace \<** *filename* **>**| **STDERR**| **STDOUT**
638-
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.
639641
640642
**Execution Control Commands**
641643
**:On Error**[ **exit** | **ignore**]
642644
Sets the action to be performed when an error occurs during script or batch execution.
643645
644646
When the **exit** option is used, **sqlcmd** exits with the appropriate error value.
645647
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.
647649
648650
[**:**] **QUIT**
649651
Causes **sqlcmd** to exit.
@@ -727,7 +729,7 @@ We recommend that you use a strong password.
727729
728730
If *timeout* is not specified, the value of the SQLCMDLOGINTIMEOUT variable is the default.
729731
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:
731733
732734
`:connect myserver\instance1`
733735
@@ -748,7 +750,7 @@ We recommend that you use a strong password.
748750
> The command is executed on the computer on which **sqlcmd** is running.
749751
750752
**: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
752754
753755
**:Help**
754756
Lists **sqlcmd** commands together with a short description of each command.
@@ -758,7 +760,7 @@ We recommend that you use a strong password.
758760
759761
- **:Error**, **:Out** and **:Perftrace** should use separate **\<***filename***>**. If the same **\<***filename***>** is used, inputs from the commands may be intermixed.
760762
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.
762764
763765
- 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.
764766
@@ -768,7 +770,7 @@ We recommend that you use a strong password.
768770
769771
**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.
770772
771-
At the command prompt, type the following:
773+
At the command prompt, type the command:
772774
773775
`sqlcmd`
774776
@@ -785,7 +787,7 @@ When you press ENTER, the following informational message is printed: "Changed d
785787
786788
This line will be followed by a separator line that is a series of dash characters. The following output shows an example.
787789
788-
Start **sqlcmd**. At the **sqlcmd** command prompt, type the following:
790+
Start **sqlcmd**. At the **sqlcmd** command prompt, type the query:
789791
790792
`USE AdventureWorks2012;`
791793
@@ -807,7 +809,7 @@ When you press ENTER, the following informational message is printed: "Changed d
807809
808810
`(2 row(s) affected)`
809811
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.
811813
812814
### <a name="OutputXML"></a> XML Output Format
813815
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
817819
> [!NOTE]
818820
> **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.
819821
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`.
821823
822824
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.
823825
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.
825827
826828
> [!NOTE]
827829
> The **:XML** command does not support the SET STATISTICS XML statement.
828830
829831
### <a name="OutputJSON"></a> JSON Output Format
830832
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.
831833
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`.
833835
834-
For more info, see [XML Output Format](#OutputXML) in this topic.
836+
For more info, see [XML Output Format](#OutputXML) in this article.
835837
836838
### Using Azure Active Directory Authentication
837839
Examples using Azure Active Directory Authentication:

0 commit comments

Comments
 (0)