Skip to content

Commit 54ca52d

Browse files
authored
Split up sqlcmd article (#34455)
1 parent 8d4cd9d commit 54ca52d

13 files changed

+910
-779
lines changed

docs/toc.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8465,6 +8465,12 @@ items:
84658465
items:
84668466
- name: sqlcmd overview
84678467
href: tools/sqlcmd/sqlcmd-utility.md
8468+
- name: Check installed version
8469+
href: tools/sqlcmd/sqlcmd-installed-version.md
8470+
- name: Download and install
8471+
href: tools/sqlcmd/sqlcmd-download-install.md
8472+
- name: sqlcmd edit and variable commands
8473+
href: tools/sqlcmd/sqlcmd-commands.md
84688474
- name: Authenticate sqlcmd with Microsoft Entra ID
84698475
href: tools/sqlcmd/sqlcmd-authentication.md
84708476
- name: Start the utility

docs/tools/sqlcmd/edit-sqlcmd-scripts-query-editor.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: You use SQLCMD scripts when you have to process Windows System comm
44
author: dlevy-msft
55
ms.author: dlevy
66
ms.reviewer: maghan, randolphwest
7-
ms.date: 08/15/2023
7+
ms.date: 07/02/2025
88
ms.service: sql
99
ms.subservice: tools-other
1010
ms.topic: how-to
@@ -77,17 +77,17 @@ To turn on SQLCMD scripting for an active Database Engine Query Editor window, u
7777
- (4 row(s) affected)
7878

7979
> [!IMPORTANT]
80-
> When executed from the command line, the **sqlcmd** utility permits full interaction with the operating system. When you use the Query Editor in **SQLCMD Mode**, you must be careful not to execute interactive statements. The Query Editor cannot respond to operating system prompts.
80+
> When executed from the command line, the **sqlcmd** utility permits full interaction with the operating system. When you use the Query Editor in **SQLCMD Mode**, you must be careful not to execute interactive statements. The Query Editor can't respond to operating system prompts.
8181
82-
For more information about how to run SQLCMD, see [**sqlcmd** utility](sqlcmd-utility.md), or take the SQLCMD tutorial.
82+
For more information about how to run SQLCMD, see [sqlcmd utility](sqlcmd-utility.md), or take the SQLCMD tutorial.
8383

8484
## Enable SQLCMD scripting by default
8585

8686
To turn on SQLCMD scripting by default, on the **Tools** menu, select **Options**, expand **Query Execution**, and **SQL Server**, select the **General** page and then check the **By default open new queries in SQLCMD Mode** box.
8787

8888
## Write and edit SQLCMD scripts
8989

90-
After enabling scripting mode, you may write SQLCMD commands and Transact-SQL statements. The following rules apply:
90+
After enabling scripting mode, you can write SQLCMD commands and Transact-SQL statements. The following rules apply:
9191

9292
- SQLCMD commands must be the first statement on a line.
9393

@@ -103,12 +103,12 @@ After enabling scripting mode, you may write SQLCMD commands and Transact-SQL st
103103

104104
- To make a clear distinction between SQLCMD commands and Transact-SQL, all SQLCMD commands need to be prefixed with a colon (`:`).
105105

106-
- The `GO` command may be used without preface or preceded by `!!:`
106+
- The `GO` command can be used without preface or preceded by `!!:`
107107

108108
- The Database Engine Query Editor supports environment variables and variables that are defined as part of a SQLCMD script, but doesn't support built-in SQLCMD or **osql** variables. SQLCMD processing by SQL Server Management Studio is case sensitive for variables. For example, PRINT '$(COMPUTERNAME)' produces the correct result, but PRINT '$(ComputerName)' returns an error.
109109

110110
> [!CAUTION]
111-
> SQL Server Management Studio uses [!INCLUDE [msCoName](../../includes/msconame-md.md)] [!INCLUDE [dnprdnshort](../../includes/dnprdnshort-md.md)] SqlClient for execution in regular and SQLCMD mode. When run from the command line, SQLCMD uses the OLE DB provider. Because different default options may apply, it is possible to get different behavior while executing the same query in SQL Server Management Studio SQLCMD Mode and in the SQLCMD utility.
111+
> SQL Server Management Studio uses [!INCLUDE [msCoName](../../includes/msconame-md.md)] [!INCLUDE [dnprdnshort](../../includes/dnprdnshort-md.md)] SqlClient for execution in regular and SQLCMD mode. When run from the command line, SQLCMD uses the OLE DB provider. Because different default options could apply, you can get different behavior while executing the same query in SQL Server Management Studio SQLCMD mode and in the **sqlcmd** utility.
112112
113113
## Supported SQLCMD syntax
114114

@@ -131,13 +131,13 @@ The Database Engine Query Editor supports the following SQLCMD script keywords:
131131
SQLCMD commands not listed above aren't supported in Query Editor. When a script containing SQLCMD keywords aren't supported is executed, the Query Editor sends an "Ignoring command *\<ignored command*>" message to the destination for each unsupported keyword. The script executes successfully, but the unsupported commands are ignored.
132132

133133
> [!CAUTION]
134-
> Because you are not starting SQLCMD from the command line, there are some limitations when running Query Editor in SQLCMD Mode. You cannot pass in command-line parameters such as variables, and, because the Query Editor cannot respond to operating system prompts, you must be careful not to execute interactive statements.
134+
> Because you don't start SQLCMD from the command line, there are some limitations when running Query Editor in SQLCMD mode. You can't pass in command-line parameters such as variables, and, because the Query Editor can't respond to operating system prompts, you must be careful not to execute interactive statements.
135135
136136
## Color coding in SQLCMD scripts
137137

138138
With SQLCMD scripting enabled, scripts are color coded. The color coding for Transact-SQL keywords remain the same. SQLCMD commands are presented with a shaded background.
139139

140-
## Example
140+
## Examples
141141

142142
The following example uses a SQLCMD statement to create an output file called testoutput.txt, executes two Transact-SQL SELECT statements along with one operating system command (to print the current directory). The resultant file contains the message output from the `DIR` statement and the results output from the Transact-SQL statements.
143143

@@ -150,6 +150,6 @@ SELECT @@SERVERNAME AS 'Server Name';
150150
GO
151151
```
152152

153-
## Next steps
153+
## Related content
154154

155155
- [sqlcmd utility](sqlcmd-utility.md)

docs/tools/sqlcmd/includes/install-go.md

Lines changed: 0 additions & 111 deletions
This file was deleted.

docs/tools/sqlcmd/includes/install-odbc.md

Lines changed: 0 additions & 40 deletions
This file was deleted.

docs/tools/sqlcmd/quickstart-sqlcmd-create-container.md

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: A quickstart that walks through using creating a new container and
44
author: dlevy-msft
55
ms.author: dlevy
66
ms.reviewer: maghan, randolphwest
7-
ms.date: 12/06/2023
7+
ms.date: 07/02/2025
88
ms.service: sql
99
ms.subservice: tools-other
1010
ms.topic: quickstart
@@ -22,7 +22,7 @@ In this quickstart, you'll use a single command in **sqlcmd** to create a new co
2222
## Prerequisites
2323

2424
- A container runtime installed, such as [Docker](https://www.docker.com/) or [Podman](https://podman.io/)
25-
- Download and install [[!INCLUDE [azure-data-studio](../../includes/azure-data-studio-short.md)]](/azure-data-studio/download-azure-data-studio)
25+
- Download and install [Azure Data Studio](/azure-data-studio/download-azure-data-studio)
2626
- Install the latest **sqlcmd**
2727

2828
## Remarks
@@ -35,7 +35,7 @@ You can reverse the order to make **sqlcmd** (ODBC) the default again.
3535

3636
## Download and install sqlcmd (Go)
3737

38-
[!INCLUDE [install-go](includes/install-go.md)]
38+
For more information, see [Download and install the sqlcmd utility](sqlcmd-download-install.md#download-and-install-sqlcmd-go).
3939

4040
## What problem will we solve?
4141

@@ -58,35 +58,35 @@ Open [!INCLUDE [azure-data-studio](../../includes/azure-data-studio-short.md)] a
5858
1. Now that you have a local copy of your database, you can run queries. Here is a query you can use to analyze spending by customer:
5959

6060
```sql
61-
SELECT bg.BuyingGroupName AS CustomerName
62-
,COUNT(DISTINCT i.InvoiceID) AS InvoiceCount
63-
,COUNT(il.InvoiceLineID) AS InvoiceLineCount
64-
,SUM(il.LineProfit) AS Profit
65-
,SUM(il.ExtendedPrice) AS ExtendedPrice
66-
FROM Sales.Invoices i
67-
INNER JOIN Sales.Customers c
68-
ON i.CustomerID = c.CustomerID
69-
INNER JOIN Sales.InvoiceLines il
70-
ON i.InvoiceID = il.InvoiceID
71-
INNER JOIN Sales.BuyingGroups bg
72-
ON c.BuyingGroupID = bg.BuyingGroupID
73-
GROUP BY bg.BuyingGroupName
61+
SELECT bg.BuyingGroupName AS CustomerName,
62+
COUNT(DISTINCT i.InvoiceID) AS InvoiceCount,
63+
COUNT(il.InvoiceLineID) AS InvoiceLineCount,
64+
SUM(il.LineProfit) AS Profit,
65+
SUM(il.ExtendedPrice) AS ExtendedPrice
66+
FROM Sales.Invoices AS i
67+
INNER JOIN Sales.Customers AS c
68+
ON i.CustomerID = c.CustomerID
69+
INNER JOIN Sales.InvoiceLines AS il
70+
ON i.InvoiceID = il.InvoiceID
71+
INNER JOIN Sales.BuyingGroups AS bg
72+
ON c.BuyingGroupID = bg.BuyingGroupID
73+
GROUP BY bg.BuyingGroupName
7474
UNION
75-
SELECT c.CustomerName
76-
,COUNT(DISTINCT i.InvoiceID) AS InvoiceCount
77-
,COUNT(il.InvoiceLineID) AS InvoiceLineCount
78-
,SUM(il.LineProfit) AS Profit
79-
,SUM(il.ExtendedPrice) AS ExtendedPrice
80-
FROM Sales.Invoices i
81-
INNER JOIN Sales.Customers c
82-
ON i.CustomerID = c.CustomerID
83-
INNER JOIN Sales.InvoiceLines il
84-
ON i.InvoiceID = il.InvoiceID
85-
LEFT JOIN Sales.BuyingGroups bg
86-
ON c.BuyingGroupID = bg.BuyingGroupID
87-
WHERE bg.BuyingGroupID IS NULL
88-
GROUP BY c.CustomerName
89-
ORDER BY Profit DESC
75+
SELECT c.CustomerName,
76+
COUNT(DISTINCT i.InvoiceID) AS InvoiceCount,
77+
COUNT(il.InvoiceLineID) AS InvoiceLineCount,
78+
SUM(il.LineProfit) AS Profit,
79+
SUM(il.ExtendedPrice) AS ExtendedPrice
80+
FROM Sales.Invoices AS i
81+
INNER JOIN Sales.Customers AS c
82+
ON i.CustomerID = c.CustomerID
83+
INNER JOIN Sales.InvoiceLines AS il
84+
ON i.InvoiceID = il.InvoiceID
85+
LEFT OUTER JOIN Sales.BuyingGroups AS bg
86+
ON c.BuyingGroupID = bg.BuyingGroupID
87+
WHERE bg.BuyingGroupID IS NULL
88+
GROUP BY c.CustomerName
89+
ORDER BY Profit DESC;
9090
```
9191

9292
## How did we solve the problem?

0 commit comments

Comments
 (0)