| title | Database Engine Query Editor | |||||||
|---|---|---|---|---|---|---|---|---|
| ms.prod | sql | |||||||
| ms.prod_service | sql-tools | |||||||
| ms.technology | ssms | |||||||
| ms.topic | conceptual | |||||||
| f1_keywords |
|
|||||||
| dev_langs |
|
|||||||
| helpviewer_keywords |
|
|||||||
| ms.assetid | 05cfae9b-96d5-4a35-a098-0bc3a548bcfc | |||||||
| author | markingmyname | |||||||
| ms.author | maghan | |||||||
| ms.reviewer | ||||||||
| ms.custom | seo-lt-2019 | |||||||
| ms.date | 02/27/2020 | |||||||
| monikerRange | >=aps-pdw-2016||=azuresqldb-current||=azure-sqldw-latest||>=sql-server-2016||=sqlallproducts-allversions||>=sql-server-linux-2017||=azuresqldb-mi-current |
[!INCLUDEappliesto-ss-asdb-asdw-xxx-md.md]
The Database Engine Query Editor is one of four editors implemented in SQL Server Management Studio (SSMS).
Use the Query Editor to create and run scripts containing Transact-SQL statements. The editor also supports running scripts that contain sqlcmd commands.
For a description of the functionality implemented in the Query Editor and the main tasks you can perform using the editor, see Query and Text Editors
The Query Editor supports linking you to the reference topic for a specific Transact-SQL statement when you select F1. To do so, highlight the name of a Transact-SQL statement and then select F1. The help search engine then searches for a topic that has an F1 help attribute that matches the string you highlighted.
If the help search engine doesn't find a topic with an F1 help keyword that exactly matches the string you highlighted, then this topic is displayed. In that case, there are two approaches to finding the help you're looking for:
-
Copy and paste the editor string you highlighted into the search tab of SQL Server Books Online and do a search.
-
Highlight only the part of the Transact-SQL statement likely to match an F1 help keyword applied to a topic and select F1 again. The search engine requires an exact match between the string you highlighted and an F1 help keyword assigned to a topic. If the string you highlighted contains elements unique to your environment, such as column or parameter names, the search engine doesn't get a match. Examples of the strings to highlight include:
-
The name of a Transact-SQL statement, such as SELECT, CREATE DATABASE or BEGIN TRANSACTION.
-
The name of a built-in function, such as SERVERPROPERTY, or @@VERSION.
-
The name of a system stored procedure table, or view, such as sys.data_spaces or sp_tableoption.
-
When the Query Editor is open, the SQL Editor toolbar appears with the following buttons.
You can also add the SQL Editor toolbar by selecting the View menu, selecting Toolbars, and then selecting SQL Editor. If you add the SQL Editor toolbar when no Query Editor windows are open, all the buttons are unavailable.
Opens the Connect to Server dialog box. Use this dialog box to establish a connection to a server.
You can also connect to your database using the context menu.
Opens the Connect to Server dialog box. Use this dialog box to establish a connection to a different server.
You can also change connections using the context menu.
Change the connection to a different database on the same server.
Executes the selected code or, if no code is selected, executes all the code in the Query Editor.
You can also Execute a query by selecting F5 or from the context menu.
Sends a cancellation request to the server. Some queries can't be canceled immediately, but must wait for a suitable cancellation condition. When transactions are canceled, delays might occur while transactions are rolled back.
You can also cancel an executing query by selecting Alt + Break.
Checks the syntax of the selected code. If no code is selected, it checks the syntax of all the code in the Query Editor window.
You can also check the code in the Query Editor by selecting Ctrl + F5.
Requests a query execution plan from the query processor without actually executing the query, and displays the plan in the Execution plan window. This plan uses index statistics as an estimate of the number of rows that are expected to be returned during each part of the query execution. The actual query plan that is used can be different from the estimated execution plan. This can occur if the number of rows that are returned is significantly different from the estimate, and the query processor changes the plan to be more efficient.
You can also display an estimated execution plan by selecting Ctrl + L or from the context menu.
Opens the Query Options dialog box. Use this dialog box to configure the default options for query execution and for query results.
You can also select Query Options from the context menu.
Specifies whether IntelliSense functionality is available in the [!INCLUDEssDE] Query Editor. This option is set by default.
You can also select IntelliSense Enabled by selecting Ctrl + B then Ctrl I, or from the context menu.
Executes the query, returns the query results, and the execution plan that was used for the query. These appear as a graphical query plan in the Execution plan window.
You can also select the Include Actual Execution Plan by selecting Ctrl + M or from the context menu.
Provides real-time insights into the query execution process as the controls flow from one query plan operator to another.
You can also select the Include Live Query Statistics from the context menu.
Includes a Client Statistics window that contains statistics about the query and about the network packets, and the elapsed time of the query.
You can also select the Include Live Query Statistics by selecting Shift + Alt + S or from the context menu.
Returns the query results as text in the Results window.
You can also return results to text by selecting Ctrl + T or from the context menu.
Returns the query results as one or more grids in the Results window. This option is usually enabled by default.
You can also return results to text by selecting Ctrl + D or from the context menu.
When the query executes, the Save Results dialog box opens. In Save In, select the folder in which you want to save the file. In File name, type the name of the file, and then select Save to save the query results as a Report file that has the .rpt extension. For advanced options, click the down-arrow on the Save button, and then select Save with Encoding.
You can also return results to text by selecting Ctrl + Shift + F or from the context menu.
Makes the current line a comment by adding a comment operator (--) at the beginning of the line.
You can also comment out a line by selecting Ctrl + K then Ctrl + C.
Makes the current line an active source statement by removing any comment operator (--) at the beginning of the line.
You can also comment out a line by selecting Ctrl + K then Ctrl + U.
Moves the text of the line to the left by removing blanks at the beginning of the line.
Moves the text of the line to the right by adding blanks at the beginning of the line.
Opens a dialog box that you can use to specify values for parameters in stored procedures and functions.
You can access the context menu by right-clicking anywhere in the query editor. The options in the context menu are similar to the SQL Editor Toolbar. With the context menu, you see the same options as Connect and Execute, but you also get other options listed such as Insert Snippet and Surround With.
A Transact-SQL code snippet is a template you can use as a starting point when writing new Transact-SQL statements in the Query Editor.
A surround-with snippet is a template you can use as a starting point when enclosing a set of Transact-SQL statements in a BEGIN, IF, or WHILE block.
There are more Connection options in the context menu compared to the toolbar options in SSMS.
-
Connect - Opens the Connect to Server dialog box. Use this dialog box to establish a connection to a server.
-
Disconnect - Disconnects the current Query Editor from the server.
-
Disconnect All Queries - Disconnects all query connections.
-
Change Connection - Opens the Connect to Server dialog box. Use this dialog box to establish a connection to a different server.
Object Explorer provides a hierarchical user interface to view and manage the objects in each instance of SQL Server. The Object Explorer Details pane presents a tabular view of instance objects, and the capability to search for specific objects. The capabilities of Object Explorer vary slightly depending on the type of server, but generally include the development features for databases, and management features for all server types.
Executes the selected code or, if no code is selected, executes all the code in the Query Editor.
Requests a query execution plan from the query processor without actually executing the query, and displays the plan in the Execution plan window. This plan uses index statistics as an estimate of the number of rows that are expected to be returned during each part of the query execution. The actual query plan that is used can be different from the estimated execution plan. This can occur if the number of rows that are returned is significantly different from the estimate, and the query processor changes the plan to be more efficient.
Specifies whether IntelliSense functionality is available in the [!INCLUDEssDE] Query Editor. This option is set by default.
SQL Server Profiler is an interface to create and manage traces and analyze and replay trace results. Events are saved in a trace file that can later be analyzed or used to replay a specific series of steps when trying to diagnose a problem.
The Microsoft Database Engine Tuning Advisor (DTA) analyzes databases and makes recommendations that you can use to optimize query performance. You can use the Database Engine Tuning Advisor to select and create an optimal set of indexes, indexed views, or table partitions without having an expert understanding of the database structure or the internals of SQL Server. Using the DTA, you can perform the following tasks.
The Query and View Designer opens when you open the definition of a view, show the results for a query or view, or create or open a query.
Executes the query, returns the query results, and the execution plan that was used for the query. These appear as a graphical query plan in the Execution plan window.
Provides real-time insights into the query execution process as the controls flow from one query plan operator to another.
Includes a Client Statistics window that contains statistics about the query and about the network packets, and the elapsed time of the query.
You can select any of the Result options you want from the context menu.
-
Results to Text - Returns the query results as text in the Results window.
-
Results to Grid - Returns the query results as one or more grids in the Results window.
-
Results to File - When the query executes, the Save Results dialog box opens. In Save In, select the folder in which you want to save the file. In File name, type the name of the file, and then select Save to save the query results as a Report file that has the .rpt extension. For advanced options, click the down-arrow on the Save button, and then select Save with Encoding.
The Properties window describes the state of an item in SQL Server Management Studio, such as a connection or a Showplan operator, and information about database objects such as tables, views, and designers.
You can use the Properties window to view the properties of the current connection. Many properties are read-only in the Properties window but can be changed elsewhere in the Management Studio. For example, the Database property of a query is read-only in the Properties window, but can be changed on the tool bar.
Opens the Query Options dialog box. Use this dialog box to configure the default options for query execution and for query results.




