| title | Save an Execution Plan in XML Format | Microsoft Docs | |||||
|---|---|---|---|---|---|---|
| ms.custom | ||||||
| ms.date | 08/21/2017 | |||||
| ms.prod | sql-server-2016 | |||||
| ms.reviewer | ||||||
| ms.suite | ||||||
| ms.technology |
|
|||||
| ms.tgt_pltfrm | ||||||
| ms.topic | article | |||||
| helpviewer_keywords |
|
|||||
| ms.assetid | c439e53b-56f3-4442-97c6-dabd48a203d8 | |||||
| caps.latest.revision | 25 | |||||
| author | JennieHubbard | |||||
| ms.author | jhubbard | |||||
| manager | jhubbard |
Use [!INCLUDEssManStudioFull] to save execution plans as an XML file, and to open them for viewing.
To use the execution plan feature in [!INCLUDEssManStudio], or to use the XML Showplan SET options, users must have the appropriate permissions to execute the [!INCLUDEtsql] query for which an execution plan is being generated, and they must be granted the SHOWPLAN permission for all databases referenced by the query.
-
In [!INCLUDEssManStudioFull] open a query editor and connect to [!INCLUDEssDE].
-
Turn SHOWPLAN_XML on with the following statement:
SET SHOWPLAN_XML ON; GOTo turn STATISTICS XML on, use the following statement:
SET STATISTICS XML ON; GO[!NOTE] SHOWPLAN_XML generates compile-time query execution plan information for a query, but does not execute the query. This is also known as the estimated execution plan. STATISTICS XML generates runtime query execution plan information for a query, and executes the query. This is also known as the actual execution plan.
-
Execute a query. Example:
USE AdventureWorks2012; GO SET SHOWPLAN_XML ON; GO -- Execute a query. SELECT BusinessEntityID FROM HumanResources.Employee WHERE NationalIDNumber = '509647174'; GO SET SHOWPLAN_XML OFF; -
In the Results pane, right-click the Microsoft SQL Server XML Showplan that contains the query plan, and then click Save Results As.
-
In the Save <Grid or Text> Results dialog box, in the Save as type box, click All files (*.*).
-
In the File name box provide a name, in the format <name**>.sqlplan**, and then click Save.
-
Generate either an estimated execution plan or an actual execution plan by using [!INCLUDEssManStudio]. For more information, see Display the Estimated Execution Plan and Display an Actual Execution Plan.
-
In the Execution plan tab of the results pane, right-click the graphical execution plan, and choose Save Execution Plan As.
As an alternative, you can also choose Save Execution Plan As on the File menu.
-
In the Save As dialog box, make sure that the Save as type is set to Execution Plan Files (*.sqlplan).
-
In the File name box provide a name, in the format <name**>.sqlplan**, and then click Save.
-
In [!INCLUDEssManStudioFull], on the File menu, choose Open, and then click File.
-
In the Open File dialog box, set Files of type to Execution Plan Files (*.sqlplan) to produce a filtered list of saved XML query plan files.
-
Select the XML query plan file that you want to view, and click Open.
As an alternative, in Windows Explorer, double-click a file with extension .sqlplan. The plan opens in [!INCLUDEssManStudio].
SET SHOWPLAN_XML (Transact-SQL)
SET STATISTICS XML (Transact-SQL)