您的位置:首页 > 博客中心 > 数据库 >

SET Statements for SQLServer

时间:2022-03-10 16:58

SET SHOWPLAN_ALL { ON | OFF }

  • It will not execute the TSQL statements.
  • It cannot be specified inside a stored procedure,must be the only statements in a batch.
  • Returns information as a set of rows that form a hierarchical tree representing the steps taken by the SQL Server query processor as it executes each statement. Each statement reflected in the output contains a single row with the text of the statement, followed by several rows with the details of the execution steps.

All the information in the resultset are estimated, no any actual statistics information.

SET SHOWPLAN_XML { ON | OFF }

  • It will not execute the TSQL statements.
  • It will return detailed information about how the statements are going to be executed in XML.

gxlsystem.com,gxl网

SET SHOWPLAN_TEXT { ON | OFF }

  • It will not execute the TSQL statements.
  • It cannot be specified inside a stored procedure,must be the only statements in a batch.
  • Returns information as a set of rows that form a hierarchical tree representing the steps taken by the SQL Server query processor as it executes each statement. Each statement reflected in the output contains a single row with the text of the statement, followed by several rows with the details of the execution steps. The table shows the column that the output contains.
  • SET SHOWPLAN_TEXT is intended to return readable output for Microsoft Win32 command prompt applications such as the osql utility. SET SHOWPLAN_ALL returns more detailed output intended to be used with programs designed to handle its output.

SET STATISTICS PROFILE { ON | OFF }

  • It will execute the TSQL statements.
  • Returns information as a set of rows that form a hierarchical tree representing the steps taken by the SQL Server query processor as it executes each statement. Each statement reflected in the output contains a single row with the text of the statement, followed by several rows with the details of the execution steps.
  • While compare with SHOWPLAN_ALL, it has two additional column Rows,Executes.


SET STATISTICS XML { ON | OFF }

  • It will execute the TSQL statements.
  • It will generate detailed information about how the statements were executed in XML.
  • SET STATISTICS XML need not be the only statement in a batch.
  • SET STATISTICS XML returns output as nvarchar(max) for applications, such as the sqlcmd utility, where the XML output is subsequently used by other tools to display and process the query plan information. The xml comply with below xsd file \Microsoft SQL Server\100\Tools\Binn\schemas\sqlserver\2004\07\showplan\showplanxml.xsd
  • SET STATISTICS PROFILE and SET STATISTICS XML are counterparts of each other. The former produces textual output; the latter produces XML output. In future versions of SQL Server, new query execution plan information will only be displayed through the SET STATISTICS XML statement, not the SET STATISTICS PROFILE statement.
  • If Include Actual Execution Plan is selected in SQL Server Management Studio, this SET option does not produce XML Showplan output. Clear the Include Actual Execution Plan button before using this SET option. 

gxlsystem.com,gxl网

SET STATISTICS TIME { ON | OFF }

  • When SET STATISTICS TIME is ON, the time statistics for a statement are displayed. When OFF, the time statistics are not displayed.
  • The setting of SET STATISTICS TIME is set at execute or run time and not at parse time.
  • Microsoft SQL Server is unable to provide accurate statistics in fiber mode, which is activated when you enable the lightweight pooling configuration option.
  • The cpu column in the sysprocesses table is only updated when a query executes with SET STATISTICS TIME ON. When SET STATISTICS TIME is OFF, 0 is returned.
  • ON and OFF settings also affect the CPU column in the Process Info View for Current Activity in SQL Server Management Studio.

SET STATISTICS IO { ON | OFF }