Skip to content

Commit 966733c

Browse files
authored
Merge pull request #36190 from shi0809/dev/shiwanigupta/sqlcmd_18_6
Add sqlcmd server_certificate related options enabled in 18.6.1.1 ODBC release
2 parents 0ef59b4 + c20a280 commit 966733c

1 file changed

Lines changed: 36 additions & 20 deletions

File tree

docs/tools/sqlcmd/sqlcmd-utility.md

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
---
22
title: Run Transact-SQL Commands with the sqlcmd Utility
33
description: The sqlcmd utility lets you enter Transact-SQL statements, system procedures, and script files using different modes, using go-mssqldb or ODBC to run T-SQL batches.
4-
author: dlevy-msft
5-
ms.author: dlevy
6-
ms.reviewer: randolphwest
7-
ms.date: 12/16/2025
4+
author: rwestMSFT
5+
ms.author: randolphwest
6+
ms.reviewer: dlevy
7+
ms.date: 01/19/2026
88
ms.service: sql
99
ms.subservice: tools-other
1010
ms.topic: concept-article
@@ -170,6 +170,7 @@ sqlcmd
170170
-i input_file
171171
-I (enable quoted identifiers)
172172
-j (Print raw error messages)
173+
-J server_certificate
173174
-k[1 | 2] (remove or replace control characters)
174175
-K application_intent
175176
-l login_timeout
@@ -219,10 +220,12 @@ The following table lists the command-line options available in **sqlcmd**, and
219220
| **[-D](#-d)** | Yes | Yes |
220221
| **[-l *login_timeout*](#-l-login_timeout)** | Yes | Yes |
221222
| **[-E](#-e-trusted)** | Yes | Yes |
223+
| **[-F *hostname_in_certificate*](#-f-hostname_in_certificate)** | Yes | Yes |
222224
| **[-g](#-g-column)** | Yes | Yes |
223225
| **[-G](#-g-entra)** | Yes | Yes |
224226
| **[-H *workstation_name*](#-h-workstation_name)** | Yes | Yes |
225227
| **[-j](#-j)** | Yes | Yes |
228+
| **[-J *server_certificate*](#-j-server_certificate)** | No | Yes |
226229
| **[-K *application_intent*](#-k-application_intent)** | Yes | Yes |
227230
| **[-M *multisubnet_failover*](#-m-multisubnet_failover)** | Yes | Yes |
228231
| **[-N\[s\|m\|o\]](#-nsmo)** | Yes | Yes |
@@ -233,7 +236,6 @@ The following table lists the command-line options available in **sqlcmd**, and
233236
| **[-Z *new_password*](#-z-exit)** | Yes | Yes |
234237
| [Input/output options](#inputoutput-options) | | |
235238
| **[-f *codepage* \| i:*codepage*\[,o:*codepage*\] \| o:*codepage*\[,i:*codepage*\]](#-f-codepage--icodepageocodepage--ocodepageicodepage)** | Yes | Yes |
236-
| **[-F *hostname_in_certificate*](#-f-hostname_in_certificate)** | Yes | Yes |
237239
| **[-i *input_file*\[,*input_file2*...\]](#-i-input_fileinput_file2)** | Yes | Yes |
238240
| **[-o *output_file*](#-o-output_file)** | Yes | Yes |
239241
| **[-r\[0 \| 1\]](#-r0--1)** | Yes | Yes |
@@ -316,6 +318,19 @@ The `-E` option ignores possible user name and password environment variable set
316318
317319
<a id="-g-column"></a>
318320

321+
#### -F *hostname_in_certificate*
322+
323+
Specifies a different, expected Common Name (CN) or Subject Alternate Name (SAN) in the server certificate to use during server certificate validation. Without this option, certificate validation ensures that the CN or SAN in the certificate matches the server name to which you're connecting. This parameter can be populated when the server name doesn't match the CN or SAN, for example, when using DNS aliases.
324+
325+
For example:
326+
327+
```console
328+
sqlcmd -S server01 -Q "SELECT TOP 100 * FROM WideWorldImporters.Sales.Orders" -A -Ns -F server01.adventure-works.com
329+
```
330+
331+
> [!NOTE]
332+
> This is different to the `-F` switch for **sqlcmd** (Go), which is used to print results using a vertical format.
333+
319334
#### -g
320335

321336
Sets the Column Encryption setting to `Enabled`. For more information, see [Always Encrypted](../../relational-databases/security/encryption/always-encrypted-database-engine.md). Only master keys stored in Windows Certificate Store are supported. The `-g` option requires at least **sqlcmd** version [13.1](https://go.microsoft.com/fwlink/?LinkID=825643). To determine your version, execute `sqlcmd -?`.
@@ -340,6 +355,20 @@ A workstation name. This option sets the **sqlcmd** scripting variable `SQLCMDWO
340355

341356
Prints raw error messages to the screen.
342357

358+
#### -J *server_certificate*
359+
360+
**Applies to**: **sqlcmd** (ODBC), Linux and macOS only. Windows isn't supported.
361+
362+
Specifies the path to a server certificate file. This file is matched against the server's connection encryption certificate. The match is done instead of standard certificate validation (expiry, host name, trust chain, etc.) The accepted certificate formats are PEM, DER, and CER.
363+
364+
Use this option when connecting to servers that use self-signed certificates or certificates issued by a private certificate authority. If encryption is enabled and certificate validation is unsuccessful, the connection fails.
365+
366+
For example:
367+
368+
```console
369+
sqlcmd -S server01 -Q "SELECT TOP 100 * FROM WideWorldImporters.Sales.Orders" -A -Ns -J /etc/ssl/certs/server_certificate.cer
370+
```
371+
343372
#### -K *application_intent*
344373

345374
Declares the application workload type when connecting to a server. The only currently supported value is `ReadOnly`. If `-K` isn't specified, **sqlcmd** doesn't support connectivity to a secondary replica in an availability group. For more information, see [Offload read-only workload to secondary replica of an Always On availability group](../../database-engine/availability-groups/windows/active-secondaries-readable-secondary-replicas-always-on-availability-groups.md).
@@ -379,15 +408,6 @@ For the **sqlcmd** (Go) utility, `-N` takes a string value that can be one of `t
379408

380409
- If both `-N` and `-C` are provided, **sqlcmd** uses their values for encryption negotiation.
381410

382-
- In **sqlcmd** (ODBC), use `-F` to specify the host name in the certificate. For example:
383-
384-
```console
385-
sqlcmd -S server01 -Q "SELECT TOP 100 * FROM WideWorldImporters.Sales.Orders" -A -Ns -F server01.adventure-works.com
386-
```
387-
388-
> [!NOTE]
389-
> This is different to the `-F` switch for **sqlcmd** (Go), which is used to print results using a vertical format.
390-
391411
#### -P *password*
392412

393413
A user-specified password. Passwords are case-sensitive. If the `-U` option is used, the `-P` option isn't used, and the `SQLCMDPASSWORD` environment variable isn't set, **sqlcmd** prompts the user for a password. We don't recommend the use of a null (blank) password, but you can specify the null password by using a pair of contiguous double-quotation marks for the parameter value (`""`).
@@ -556,10 +576,6 @@ Enter `chcp` at the command prompt to verify the code page of `cmd.exe`.
556576
> [!NOTE]
557577
> On Linux, the codepage number is a numeric value that specifies an installed Linux code page (available since 17.5.1.1).
558578
559-
#### -F *hostname_in_certificate*
560-
561-
Specifies a different, expected Common Name (CN) or Subject Alternate Name (SAN) in the server certificate to use during server certificate validation. Without this option, certificate validation ensures that the CN or SAN in the certificate matches the server name to which you're connecting. This parameter can be populated when the server name doesn't match the CN or SAN, for example, when using DNS aliases.
562-
563579
#### -i *input_file*[,*input_file2*...]
564580

565581
Identifies the file that contains a batch of Transact-SQL statements or stored procedures. Multiple files might be specified that are read and processed in order. Don't use any spaces between file names. **sqlcmd** checks first to see whether all the specified files exist. If one or more files don't exist, **sqlcmd** exits. The `-i` and the `-Q`/`-q` options are mutually exclusive.
@@ -628,7 +644,7 @@ Redirects the error message output to the screen (`stderr`). If you don't specif
628644
629645
#### -R
630646

631-
**Applies to**: ODBC **sqlcmd** only.
647+
**Applies to**: **sqlcmd** (ODBC) only.
632648

633649
Causes **sqlcmd** to localize numeric, currency, date, and time columns retrieved from [!INCLUDE [ssnoversion-md](../../includes/ssnoversion-md.md)] based on the client's locale. By default, these columns are displayed using the server's regional settings.
634650

@@ -652,7 +668,7 @@ Writes input scripts to the standard output device (`stdout`).
652668

653669
#### -I
654670

655-
**Applies to**: ODBC **sqlcmd** only.
671+
**Applies to**: **sqlcmd** (ODBC) only.
656672

657673
Sets the `SET QUOTED_IDENTIFIER` connection option to `ON`. The default setting is `OFF`. For more information, see [SET QUOTED_IDENTIFIER](../../t-sql/statements/set-quoted-identifier-transact-sql.md).
658674

0 commit comments

Comments
 (0)