When SQL Server executes a SQL statement, it uses the query optimizer to construct an execution plan for the statement. An execution plan is a series of steps that produces the desired result for the query. SQL Server's Showplan feature allows users to see the execution plan that the optimizer creates for a specific statement. This information can be used to help decide how a statement's performance might be improved, either by changing the query or by adding a database index. There are ways to generate an execution plan in MS SQL Server (note: the examples below apply to MS SQL Server 7.0 and SQL Server 2000):
Using Showplan with the Set statement
There are two Transact-SQL statements that can be used to see a SQL query statement's execution plan:
Set Showplan_Text On
or
Set Showplan_All On
Both statements cause SQL Server to not execute subsequent SQL statements for the connection until another Showplan_Text or Showplan_All command is executed with "Off" as the new setting. When Showplan_Text or Showplan_All is in effect, SQL Server returns information about the execution plan for each subsequently executed statement. Showplan_Text causes basic information to be returned in a format suitable for users to read directly, whereas Showplan_All returns more comprehensive information in a result table suitable for processing by an application program.
Given below is an example of Showplan_Text:
Set Showplan_Text On
go
Select * From S_ORG_EXT
Order by NAME
StmtText
—————————————–
Select * From S_ORG_EXT
Order by NAME
(1 row(s) affected)
StmtText
——————————————————————————————
|–Clustered Index Scan(OBJECT:([sb995ms70].[dbo].[S_ORG_EXT].[S_ORG_EXT_U1]), ORDERED)
(1 row(s) affected)
The output is structured as a tree. In this example, the first execution step is the clustered index scan, and the results of this step are used in a sort step. The results of the sort step are returned to the application using Graphical Showplan. Use Query Analyzer in MS SQL Server 7.0 to review execution plan for a statement. Simply enter the statement in the query pane and select Query > Display Estimated Execution Plan menu. This will display a flow diagram for the execution plan. To print the graphical plan, click the cursor in the SQL Execution Plan pane to make it active and select Print from the File menu.
http://msdn.microsoft.com/en-us/library/ms187713.aspx