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/sqlcmd-utility.md
+36-20Lines changed: 36 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,10 @@
1
1
---
2
2
title: Run Transact-SQL Commands with the sqlcmd Utility
3
3
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
8
8
ms.service: sql
9
9
ms.subservice: tools-other
10
10
ms.topic: concept-article
@@ -170,6 +170,7 @@ sqlcmd
170
170
-i input_file
171
171
-I (enable quoted identifiers)
172
172
-j (Print raw error messages)
173
+
-J server_certificate
173
174
-k[1 | 2] (remove or replace control characters)
174
175
-K application_intent
175
176
-l login_timeout
@@ -219,10 +220,12 @@ The following table lists the command-line options available in **sqlcmd**, and
@@ -316,6 +318,19 @@ The `-E` option ignores possible user name and password environment variable set
316
318
317
319
<aid="-g-column"></a>
318
320
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
+
319
334
#### -g
320
335
321
336
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
340
355
341
356
Prints raw error messages to the screen.
342
357
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
+
343
372
#### -K *application_intent*
344
373
345
374
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
379
408
380
409
- If both `-N` and `-C` are provided, **sqlcmd** uses their values for encryption negotiation.
381
410
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
-
391
411
#### -P *password*
392
412
393
413
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`.
556
576
> [!NOTE]
557
577
> On Linux, the codepage number is a numeric value that specifies an installed Linux code page (available since 17.5.1.1).
558
578
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
-
563
579
#### -i *input_file*[,*input_file2*...]
564
580
565
581
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
628
644
629
645
#### -R
630
646
631
-
**Applies to**: ODBC **sqlcmd** only.
647
+
**Applies to**: **sqlcmd** (ODBC) only.
632
648
633
649
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.
634
650
@@ -652,7 +668,7 @@ Writes input scripts to the standard output device (`stdout`).
652
668
653
669
#### -I
654
670
655
-
**Applies to**: ODBC **sqlcmd** only.
671
+
**Applies to**: **sqlcmd** (ODBC) only.
656
672
657
673
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).
0 commit comments