Bagikan melalui


Query Results Overview

After you open or create a database query in the Transact-SQL editor, you typically execute that query and examine the results. When you execute a query, the editor uses the Results pane to communicate the results of that query. The Results pane contains up to five tabs: Results, Messages, Client Statistics, and Execution plan. The specific tabs you see depend on the following factors.

  • Show results setting: Choose to show results in one of three ways: Results as Grid (default), Results As Text, or Results as File. This determines if the Results tab, the Messages tab, or both are used to communicate results.

  • Client statistics setting: If you enable the Include Client Statistics setting, the Client Statistics tab will be used to display statistics.

  • Execution plan setting: If you click Display Estimated Execution Plan or enable the Include Actual Execution Plan setting, the Execution plan tab is used to display an execution plan.

You can resize the Results pane by using the splitter bar at the edge of the window.

Results Tab

If you choose to show results as grid, the Results tab displays the data that your query retrieved from the database. The data consists of one or more independent sets of results. Only queries that return results, such as a query that contains a SELECT statement or a stored procedure, display data on the Results tab. If a query is executed successfully but no result set is returned, the Results tab does not appear.

If you choose to show results as text, then all results and messages appear on the Results tab, and the Messages tab does not appear. If you choose to save your results as a file, you are prompted for the name of the file to which your results will be saved. Messages appear on the Messages tab.

The results of the Validate SQL Syntax command always appear on the Results tab.

You can perform the following actions when you right-click the Results tab:

  • Copy
    Copies the selected data (a cell or a range of cells) to the Clipboard.

  • Select All
    Selects all rows and columns in the list of results. You typically perform this action before you copy data.

  • Save Results As
    Saves the contents of the Results tab to a .CSV file that you specify. Results will be saved to a .TXT file if you choose to display results as text.

  • Properties Window
    Displays the properties window.

Multiple Result Sets

If you execute a set of Transact-SQL statements that produce multiple result sets, the sets appear on the Results tab, separated by splitter bars. You can resize individual result sets using the splitter bars, and you can press F6 and SHIFT+F6 to navigate between the results and the panes.

Messages Tab

The Messages tab displays any messages that the database server returns when you execute the queries. These messages include text output, such as the results of a PRINT statement. The Messages tab also includes custom messages, such as when you execute a batch using "GO 10". Queries that do not retrieve data, such as update queries, also display a message on the Messages tab.

Both success and failure messages appear on this tab, in the order in which the server returned them. If you choose to display results as text, the contents of the Messages tab instead appear on the Results tab.

You can perform the following actions when you right-click the Messages tab:

  • Copy
    Copies the selected text to the Clipboard.

  • Select All
    Selects all messages. You typically perform this action before you copy messages.

  • Save Results As
    Saves the contents of the Messages tab to a .TXT file that you specify.

  • Properties Window
    Displays the properties window.

Client Statistics Tab

The Client Statistics tab contains information about each execution of a query in that instance of the Transact-SQL editor (even if it is a different query). A column is added every time that you run the query, and the averages are updated. Each cell indicates not only the value for that execution but also whether that value has changed. Increases are indicated by an up-arrow, and decreases by a down-arrow, and no change from the value for the previous execution is indicated by a right-arrow.

Note

Each execution adds a column to the right of the Statistic column and to the left of the columns for previous executions.

For the first execution, all results are marked as no change. Each column is labeled with the time at which the query was executed. Columns are added on the left side.

The Client Statistics tab appears only if you have chosen to include client statistics when you execute your queries. For more information, see How to: Control the Gathering and Display of Client Statistics.

You can perform the following actions when you right-click the Client Statistics tab:

  • Copy
    Copies the selected rows to the Clipboard.

  • Select All
    Selects all rows. You typically perform this action before you copy rows.

  • Properties Window
    Displays the properties window.

Available Statistics

The following statistics are available on the Client Statistics tab:

  • Number of INSERT, DELETE, and UPDATE statements
    The number of INSERT, DELETE, or UPDATE statements that were executed as a result of your query.

  • Rows affected by INSERT, DELETE, and UPDATE statements
    The number of rows that were affected by INSERT, DELETE, or UPDATE statements that were executed as part of your query.

  • Number of SELECT statements
    The number of SELECT statements that were executed through the connection as part of your query execution. This number includes FETCH statements to retrieve rows from cursors.

  • Rows returned by SELECT statements
    The number of rows that were selected as part of your query execution. This number reflects all the rows generated by Transact-SQL statements, even those that were not actually consumed by the caller (if, for example, you cancel execution). This number also includes FETCH statements to retrieve rows from cursors.

  • Number of transactions
    The number of user transactions that were started as part of your query execution, including rollbacks.

  • Number of server roundtrips
    The number of times that the connection sent commands to the server and received a reply as part of query execution.

  • TDS packets sent from client
    The number of TDS packets that the client sent to the database server during query execution. Large commands can require multiple buffers. For example, if a large command is sent to the server and requires six packets, the number of server roundtrips is incremented by one, and the number of TDS packets that the client sent is incremented by six.

  • TDS packets received from server
    The number of TDS packets that the client received from the instance of SQL Server.

  • Bytes sent from client
    The number of bytes that the client sent to the instance of SQL Server during query execution.

  • Bytes received from server
    The number of bytes that the client received from the instance of SQL Server during query execution.

  • Client processing time
    The cumulative amount of time that the client spent executing code while the query was executed.

  • Total execution time
    The cumulative amount of time (in milliseconds) that the client spent processing while the query was executed, including the time that the client spent waiting for replies from the server as well as the time spent executing code.

  • Wait time on server replies
    The cumulative amount of time (in milliseconds) that the client spent while it waited for the server to reply.

Execution Plan Tab

The Execution plan tab displays the estimated or actual execution plan for the queries that are selected. When estimated execution plans are generated, the Transact-SQL queries or batches do not execute. Instead, the execution plan that is generated displays the query execution plan that the instance of SQL Server would most probably use if the queries were actually executed.

A connection to an instance of SQL Server is required in order to display the estimated or actual execution plan. To access the menu containing the Display Estimated Execution Plan or the Include Actual Execution Plan buttons, right-click the Transact-SQL editor window or click Data and then Transact-SQL Editor. To view the actual execution plan, you must also execute your query or batch.

To view additional information, pause the mouse over the logical and physical operator icons and view the description and properties of the operator in the displayed ToolTip. Alternatively, you can view operator properties in the properties window. If the properties window is not visible, right-click an operator and click Properties Window. Select an operator to view its properties.

To use this feature, users must have the appropriate permissions to execute the Transact-SQL query for which a graphical execution plan is being generated, and they must be granted the SHOWPLAN permission for all databases referenced by the query. For more information, see Showplan Security.

You can perform the following actions when you right-click the Execution plan tab:

  • Save Results As
    Saves the contents of the Execution plan tab to an execution plan (.sqlplan) file that you specify.

  • Properties Window
    Displays the properties window.

See Also

Tasks

How to: Execute a Query

Reference

Transact-SQL Editor Options (Query Execution/General)

Concepts

Editing Database Scripts and Objects with the Transact-SQL Editor