To execute scripts, press F5; or click Execute on the toolbar; or on the Query menu, click Execute. If a part of the code is selected, only that part is executed. If no code is selected, all the code in the Query Editor is executed.
To obtain help with Transact-SQL syntax, select a keyword in Query Editor, and then click F1.
For dynamic help with Transact-SQL syntax, on the Help menu, click Dynamic Help. This opens the Dynamic Help component. With Dynamic Help, help topics appear in the Dynamic Help window when keywords are typed in the Query Editor.
The Query Editor supports IntelliSense functionality, such as word and parameter completion. For more information, see Using IntelliSense.
Enabling IntelliSense for large Transact-SQL scripts can reduce the performance of slow computers. For information about how to limit the size of Transact-SQL scripts for which IntelliSense is enabled, see Options (Text Editor/Transact-SQL/IntelliSense).
The Query Editor provides the Transact-SQL debugger that you can use to help debug Transact-SQL scripts and statements. For more information, see Using the Transact-SQL Debugger.
Errors messages are displayed in the following areas:
In a Messages tab at the bottom of the window for errors that are returned by the SQL Server Database Engine.
When the Database Engine Query Editor is open, the SQL Editor toolbar appears with the following buttons.
Opens the Connect to Server dialog box. Use this dialog box to establish a connection to a server.
Disconnects the current Query Editor from the server.
Opens the Connect to Server dialog box. Use this dialog box to establish a connection to a different server.
New Query with Current Connection
Opens a new Query Editor window and uses the connection information from the current Query Editor window.
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.
Enables the Transact-SQL debugger. This debugger supports debugging actions such as setting breakpoints, watching variables, and stepping through code.
Cancel Executing Query
Sends a cancellation request to the server. Some queries cannot be canceled immediately, but must wait for a suitable cancellation condition. When transactions are canceled, delays might occur while transactions are rolled back.
Check the syntax of the selected code. If no code is selected, checks the syntax of the all code in the Query Editor window.
Display Estimated Execution Plan
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.
Opens the Query Options dialog box. Use this dialog box to configure the default options for query execution and for query results.
Specifies whether IntelliSense functionality is available in the Database Engine Query Editor.
Include Actual Execution Plan
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.
Include Client Statistics
Includes a Client Statistics window that contains statistics about the query and about the network packets, and the elapsed time of the query.
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 click 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 click Save with Encoding.
Makes the current line a comment by adding a comment operator (--) at the beginning of the line.
Makes the current line an active source statement by removing any comment operator (--) at the beginning of the line.
Decrease Line Indent
Moves the text of the line to the left by removing blanks at the beginning of the line.
Increase Line Indent
Moves the text of the line to the right by adding blanks at the beginning of the line.
Specify Values for Template Parameters
Opens a dialog box that you can use to specify values for parameters in stored procedures and functions.
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 Database Engine Query Editor windows are open, all the buttons are unavailable.
When a Database Engine Query Editor window is open, you can add the Debug toolbar by selecting the View menu, selecting Toolbars, and then selecting Debug. If you add the Debug toolbar when no Database Engine Query Editor windows are open, all the buttons are unavailable.
Runs the code in the Database Engine Query Editor window until a breakpoint is encountered.
Sets the debugger to break all processes to which the debugger is attached when a break occurs.
Takes the selected Database Engine Query Editor window out of debug mode, and restores the standard execution mode.
Show Next Statement
Moves the cursor to the next statement to be executed.
Run the statement after the current statement.
Skip the statement that is immediately after the current statement and run the statement that follows that one.
Step back to the next highest calling level (function, stored procedure, or trigger).
Opens either the Breakpoint window or the Immediate window.