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/edit-sqlcmd-scripts-query-editor.md
+9-9Lines changed: 9 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ description: You use SQLCMD scripts when you have to process Windows System comm
4
4
author: dlevy-msft
5
5
ms.author: dlevy
6
6
ms.reviewer: maghan, randolphwest
7
-
ms.date: 08/15/2023
7
+
ms.date: 07/02/2025
8
8
ms.service: sql
9
9
ms.subservice: tools-other
10
10
ms.topic: how-to
@@ -77,17 +77,17 @@ To turn on SQLCMD scripting for an active Database Engine Query Editor window, u
77
77
- (4 row(s) affected)
78
78
79
79
> [!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.
81
81
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.
83
83
84
84
## Enable SQLCMD scripting by default
85
85
86
86
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.
87
87
88
88
## Write and edit SQLCMD scripts
89
89
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:
91
91
92
92
- SQLCMD commands must be the first statement on a line.
93
93
@@ -103,12 +103,12 @@ After enabling scripting mode, you may write SQLCMD commands and Transact-SQL st
103
103
104
104
- To make a clear distinction between SQLCMD commands and Transact-SQL, all SQLCMD commands need to be prefixed with a colon (`:`).
105
105
106
-
- The `GO` command may be used without preface or preceded by `!!:`
106
+
- The `GO` command can be used without preface or preceded by `!!:`
107
107
108
108
- 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.
109
109
110
110
> [!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.
112
112
113
113
## Supported SQLCMD syntax
114
114
@@ -131,13 +131,13 @@ The Database Engine Query Editor supports the following SQLCMD script keywords:
131
131
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.
132
132
133
133
> [!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.
135
135
136
136
## Color coding in SQLCMD scripts
137
137
138
138
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.
139
139
140
-
## Example
140
+
## Examples
141
141
142
142
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.
143
143
@@ -150,6 +150,6 @@ SELECT @@SERVERNAME AS 'Server Name';
0 commit comments