Professional Documents
Culture Documents
Dissecting
SQL Server
Execution
Plans
By Grant Fritchey
In association with
ISBN: 978-1-906434-01-4
Shelving: Database/SQL Server
www.simpletalkpublishing.com
"
#!
+,
- %#
."
+
+
+
* 0*
+
)
+
.)
1
2
+
)
* +
*
3
+
*
$%
%
.................................................................................................................................................... 4
-
...................................................................................................................................... #
*
.................................................................................................................................%%
............................................................................................................................................%
.................................................................................................................................................%4
%5 67
........................................................................................................%&
:
; .........................................................................%&
...........................................................................................................................%&
:
<
= .............................................................................................................%$
67
......................................................................................................................%
67
67
>
................................................................................%
.............................................................................................................%
6
67
67
, )) ........................................
......................................................................................................... %
........................................................................................................................ %
.................................................................................................................................. %
@?A
................................................................................................................................ %
............................................................................................................................. %
.............................................................................................................................
>3
B * 67
.................................................................
67
................................................................................
.................................................................................................... (
.......................................................................................................... (
67
7 67
......................................................................................... $
7
7
...........................................................................................................
........................................................................................ #
6
@?A
...........................................................................................
.................................................................................................
@?A67
-
.............................................................................. '
@?A
................................................................... #
..............................................................................................................(
@?A
.................................................................................(
C
67
:A
) ...........................................................(
.............................................................................................................((
*
@?A
.......................................................................................((
........................................................................................................................................(&
5>
67
67
:
................................................($
.........................................................................($
...............................................................................................................(
...............................................................................................................(#
7
..........................................................................................................(
"
D
) !
......................................................................................................'%
C .............................................................................................................................'
.................................................................................................................................'&
>,A
C ............................................................................................................................'$
E
9
.....................................................................................................................................4
?
/E 0....................................................................................................................4
7
"
...............................................................................................................4'
E ...................................................................................................................44
........................................................................................................................44
E .................................................................................................................................4&
8 96>6
67
..........................................................................................................4
><C !F
<>,6> !F ...........................................................&
.............................................................................................................................................&
9
/-
0.........................................................................................................&
...........................................................................................................................................&(
>
>*
67
+C
...............................................................................................&'
67
.............................................................................&&
.....................................................................................................................&&
C
...................................................................................................................&$
....................................................................................................................&
........................................................................................................................................$
(5
@?A67
7 67
-
@?A67
- -
.......................................................$%
...................................................................................................................$%
- 6
) !
:
............................................................................................$%
7:
...........................................................................................$(
.................................................................................................................$$
@?A
@?A
........................................................................................................$
............................................................................................................... %
........................................................................................................................................ %
'5 C
7:
.................................................................. (
........................................................................................................................ (
,
.............................................................................................................................. '
-,
................................................................................... '
AF ............................................................................................. $
67
......................................................................................................#
B * ..............................................................................................................................................#
B * ........................................................................................................................#
7 B * ..........................................................................................................................#(
7 ...........................................................................................................................................#4
7 57
...............................................................#4
.......................................................................................................................#
7 ............................................................................................................%
.....................................................................................................................................% %
45
67
.......................................................................% (
................................................................................................................................% (
....................................................................................................................................% #
<> 6 <>,6>..................................................................................................................%%
?-@,< ..............................................................................................................................%%%
<
? H6 <>..................................................................................................................%%(
A-"....................................................................................................................%%
D66
A-" .........................................................................................................................%%
D66
6@ -", B 68 ................................................................................................................%%
?-@>6 C> <" ..............................................................................................................%%#
C 6 A-".............................................................................................................................%%#
E
....................................................................................................................................%
..................................................................................................................................%
9
7..................................................................................................................% (
&5
<
...........................................................................................................%
...........................................................................................................................%
<
..................................................................................................................% #
<
?
.................................................................................................................%('
<
...........................................................................................................%('
......................................................................................................................%('
D6F 6
....................................................................................................................%($
>6-,I<"AF
..........................................................................................................%(#
.........................................................................................................%(#
......................................................................................................................................%''
$5 @?A
67
.................................................................................................%'&
<> @?A...................................................................................................................................%'&
< 6"@?A................................................................................................................................%4%
@:
........................................................................................................................................%4'
.........................................................................................................%4'
.......................................................................................................%4&
......................................................................................................................................%4$
5>
..............................................................................................................%&
A
67
.....................................................................................%&
67
? 7,
.................................................................................................%&'
...................................................................................................%&'
)
............................................................................................%&4
! ;.........................................................................................%&&
67
67
9 *
..................................................................................%&&
))
) 67
67
.......................................................%&#
.....................................................................%$
< 1
...............................................................................................................%$
:A
...................................................................................................................%$(
...........................................................................................................%$'
-
..................................................................................................%$4
.................................................................................................................................%$4
C
) 67
....................................................................%$4
......................................................................................................................................%$$
7......................................................................................................................................................%$
&$'
'
$(
*
,!- )
.
1
B!+ J
.9
)&. +
))
+
)
)
-
.9
)
/"6 C 0.
<
*
)
+
*
.
*
+
?
+
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
#
)
)
)
*
3
3
3
*
* +
+ )
) 3
*
))
/4$
* 7
.
*
+
+
))+ *
*
5
)*
*
DBCC FREEPROCCACHE
F L
*
)
1
+ *
7
*
. 8
*
*
3
5
=
)
SELECT
[cp].[refcounts]
,[cp].[usecounts]
,[cp].[objtype]
,[st].[dbid]
,[st].[objectid]
,[st].[text]
,[qp].[query_plan]
sys.dm_exec_cached_plans cp
CROSS APPLY sys.dm_exec_sql_text(cp.plan_handle) st
CROSS APPLY sys.dm_exec_query_plan(cp.plan_handle) qp ;
FROM
3
:A. F
:A
@?A
@?A
* !
+
+
7
* L
+
. 9 *
7
4
))
))
))
))
*
.
)
0
+
)
))
7
/
2'#
+
)
* L *
5
*
TempTable;
)
+
+
."
/ *
+
)
4 #
)
.
)*
*
7
))
)
'.
%5 67
=+*
:A.
*
)
+
.>
) .
)
/
67
= +
1 .
7 .
7
L
3
)
* *
###
8
)
. 8
* +
0 *
7
*
7
))
L
:A
))
.
.
)
).
))
)
) 7
7
0+
7
@?A
*
,!-L
"
3
-
)
)
+
7
.!
40 / 5 37 555
7
)
3
40 / 5 376$-65
#8 % .
*
46 62462&4
25$9
)
7
)
)
7
40 / 5 37 55 7
/+
@?A
)
@?A)
40 / 5 37- 55
46 62462&47- 55
67
7
@?A)
*
:A
*
+
)@?A
-
))
5
=
7
7
.
:A
+
.9 *
)
*
+
.<
.
+
))
)
) :A
)
))
))
*
7
7
/ ))
-
)7 0+
8
)
* *
)
)
*
) *
.
))
"
) *
).- )
/ 5QQ***.
)
*
7
7+ L
)
:A
'
5QQ***.
7.
Q?
*
0.
:A
7. +
4
'
#6 #
.F
,!
+
7
)
8
)))
.
)
7
3
.,
+
))
)@?A+
)
+
7
.
3
))
*
*
+
) *
+
4 : #
)O
( 2
34
7
*
7 : +
.
+
*
*
7
* L *
)
.<
3
L
+
*
.>
* 5
"
)
3
?
6
3
)
+
SELECT *
FROM [dbo].[DatabaseLog];
+
3
*L
*
*5
7
)
+
. <
%5 67
8 L
8
*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)
; 8 +
@?A67
)
*
7 67
*L
)
3
7 7
<"+ 7
+*
)
7
. 9
40 / 5 37
)
+
40 / 5 37
7
3
+ *
55
55
7 +)
9<8 A-"I-AA
:A
+
. L
)
& $ 6$+
+
7
+*
.
< 6$
40 / 5 37 55 ))+
)
<$5$6$
' (
7
+
. )
*
8
)
3
*
) 40 / 5 376$-6.
#8 % + *
7
+
*
40 / 5 37 55 )
8 )
*
+
40 / 5 37 55
5
SET STATISTICS PROFILE OFF
"
8 L
) *
*
5
GO
SELECT *
%5 67
FROM [dbo].[DatabaseLog];
GO
SET SHOWPLAN_ALL OFF;
GO
"
7
.
* )
*
+
K
*
+
.
)K
L 3
L
.F
/G0
.
)
*
)
.
)
$
/
1
*
+
.
7 7
.
4$5$&6
*
*
*..
- *
* 5
.9
)
+*
.?
)
3
2 *
*
3
)
+
40 / 5 37 55 *
L
)
.
)
L
)
*
+
#4
"
.
6 & +
, )
A
0+ *
.
/+
@?A
4.
*
)) )
:A
/+
@?A
SET SHOWPLAN_XML ON
- ) 40 / 5 37 55+
40 / 5 37- 5
7
:A
) *+
)
)
+
)
) @?A
9<8 A-"I@?A ))
)
3
:A 7
.
@?A
7
.-
+ L
)
(
SET STATISTICS XML ON
"
/+
<
GO
SET SHOWPLAN_XML ON;
GO
SELECT *
FROM [dbo].[DatabaseLog];
SET SHOWPLAN_XML OFF;
GO
"
$5
@?A)
7
:A
@?A )
?
0. F
/ )
/ ? 0. F
)
*
*
*
**
7+
)
# 6
@?A
)*
+
@?A)
.
.
-
) )
)
7
*
*
"
+
+
*
+
*
) )
* * L
7
.
. L
.
http://schemas.microsoft.com/sqlserver/2004/07/showplan/.
4
!
7
*L
.8
*
+*
.
+
)+*
3
)
3
)
# 5
+*L
. " 7+
)
)+
%5 67
(%
)
40 / 5 37 55. "
7 . )
7
+
3
7
.
-)
+*
*
7
=
&
# 4
+
)
*
)+ )
*
5 '
+*
*L
* +
"
)*
0.
, )
*
))
+
)& #
5
)
5
<OutputList>
<ColumnReference Database="[AdventureWorks]"
Table="[DatabaseLog]" Column="DatabaseLogID" />
<ColumnReference Database="[AdventureWorks]"
Table="[DatabaseLog]" Column="PostTime" />
<ColumnReference Database="[AdventureWorks]"
Table="[DatabaseLog]" Column="DatabaseUser" />
<ColumnReference Database="[AdventureWorks]"
Table="[DatabaseLog]" Column="Event" />
<ColumnReference Database="[AdventureWorks]"
Table="[DatabaseLog]" Column="Schema" />
<ColumnReference Database="[AdventureWorks]"
Table="[DatabaseLog]" Column="Object" />
<ColumnReference Database="[AdventureWorks]"
Table="[DatabaseLog]" Column="TSQL" />
<ColumnReference Database="[AdventureWorks]"
Table="[DatabaseLog]" Column="XmlEvent" />
</OutputList>
@?A
3 .
!
Schema="[dbo]"
Schema="[dbo]"
Schema="[dbo]"
Schema="[dbo]"
Schema="[dbo]"
Schema="[dbo]"
Schema="[dbo]"
Schema="[dbo]"
+ )
) )
(
<DefinedValues>
<DefinedValue>
<ColumnReference Database="[AdventureWorks]" Schema="[dbo]"
Table="[DatabaseLog]" Column="DatabaseLogID" />
</DefinedValue>
<DefinedValue>
<output cropped>..
/+
"
7
- .K F
*
K
)
*
)
K. 3
) +*
@?A 7
# %
!
7
*
.
*/
)
*
,!- )
@?A
7
@?A
*
)
)
:A
*
*
'
7
.F
+ )
.-
+
1
3
:A
7
*
)
4
.F
)
@?A 7
+
)
) + ) 7
+
+
L
)
* )
*
+
) +
:A
+
+
*
C0
)
*
'
<
+
3
4
7
7
.
3
3
:A/
.<
*. -
:A
*
*
@?A+
@?A
<
*
.
)
*
"
9 *
))
@?A
*. )
!
) )
@?A
@?A *
*
+
*
*
@?A )
)
.
)7
7
# ) .
<
KT.TK
.K
:A
)
.
.
)
5QQ
)
.
)
).
+
Q
.'
)
Q %$($4$.
70.
%5 67
((
*5
*
7
) 3
*
40 / 5 376$-6
:A
.
:A 4
+
*
)
)
*
@?A. 8 L
)
7 7
+
)
)
.
4 : # 6%(
+5
+
*
)
)
.
)
)
.
4 : # ##5
)
3
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
)
.6
L
)*
*
+*
0*
.8 *
* *
.
7
*
)
)$#
) *
+
/
7
/4 #
+*
.?
3
)
)
6 #4
L
0. 9 *
=
+
$# )
)
. )
!
<
http://msdn2.microsoft.com/en-us/library/ms175913.aspx
5 !
#
3
7
+
###
,
#
.
+
?
/,?A0
+
))
*
)
)7
&
5 ! ! #
+,
*
+ )+
*L )
.!
<
+ * * )
. <)
,!,!-+
)
+
)
)
5
4 #
#+
:A
:A
/>
0+ 8
.
+
+
K
+*
*
K
*
+* * )
*
*
+
&#
2 %4
.
)
&#
2 %4
3
2
. #
%4
3
2
. #
%4
6 #4
2< 5
! 1
&
4 #
A=
$ ! 4
&
#
-
>
.
73
<
( !! ! +
.!
)
7
)* * +
3
+
*
> P
*
P
)
)
))
.-
*
)
.?
..)
#
A L
)
-
))
SELECT *
FROM
Person.Contact
O
03
8&
5>
"
67
) !
(#
*+
)
7
*
@7&
* %##$ .
7
) *
:A
7
+*
-
/
+
.
.
)
*
+*
*+
77
3
7.
)
0. 7+
7 +
3
* *
2<
7
-
7&
7
3
. )
) +
3
+
7+
7
) *
. )
/0$ $
.>
*
:A
))
/0$ $
'
SELECT *
FROM
Person.Contact
"
7
*
))
7
. -
+*
7
/
) +
7
7+
7
7
.
3
7 )
7
7
3
7
+*
+
&#
)
2 %4
@7&
7&
7)
.
)
+
7.
8&
*+ )
:A
%
+*
7.
0. - #
*
.
3
)
*
+
2+ *
*+
5>
67
"
*
*
) !
*)
*
8&
'%
=.
A L
))
75
SELECT
FROM
WHERE
ContactID
Person.Contact
EmailAddress LIKE 'sab%'
7
7$
7+ 2-7&
3 6$5
7
7
+
*. ."
."
#
*
)
?
*
)
).
7
*
)7
'
"
7
.C
7
=
7
7
+
.,
)
)
)!
*
7
7+
7+
7+
Q<
)
P
5'"
A L
5
SELECT
ContactID,
LastName,
)*
5>
67
'(
Phone
Person.Contact
EmailAddress LIKE 'sab%'
FROM
WHERE
"
) !
'5
+*
O>
)
2-7&
+
7$
#
3 +
*
3 +
7
+)
7.
.-
3
7+
)
7
7
7
3
.
8
*
*
*
*)
&
2<
4+
''
"
&
@ 5
*+*
)
+
&.
@7&
7&
5 3
2<
5>
"
-D
67
) !
'4
- D
&
A
+
/
)0.
7/ )
) D
)
7+
7.
=
* ,0
*
*
7. !
3 +
) )
)
7
*
)
)
.
-D
A C
)
*
"
*
)
&
+*
'&
"
"
A
.
)
A
A
1
*
*
1
+
D
* )
)1
A
)
7
7*
0+
3
A
+
"
. )
D
"
A
.
)
3
)7
* *
*
7
SELECT
FROM
[dbo].[DatabaseLog]
%.
+
* )
5>
67
) !
'$
"
)
+
*
3
.+ *
.<
*
*
7
5'"
)
/
+
)
*.
(,
*
=
3
7
)
*
*
7
.8
7 7
+
+
) *
+ )
*
.
+
*
)*
*
1 0 )
) )
)
*
*
* )* * .
+
*+
7
)
* )
* )
3
7. -
'
)*
)
+ *
.
SELECT
FROM
WHERE
"
<
5 !3
)
))
*
[dbo].[DatabaseLog]
DatabaseLogID = 1
)
.8
+
3
7
3
)
= )
)
)
*
7. 9 *
7
/0$ $
*
*
;
2<
5>
"
67
) !
'#
)
K!
+*
K!
% K
) 3
<
.
" 7+
=
/
*
.
* 0+
Q<
+*
>,A C +*
L
*
+
*
)
))
*
"
A
)
70+
)
7/
L
7
)
.
.
)
"
##
)
A
>,A
.
0*
+*
+
/
)
L
K!
3
)
.
)
.!
*+
Q< P
7+
)
+
>,
*
) >,
*
3 +
7.
# 7
C
*+ *
3 .
3
*
5
)
3
*
*
.A L
3
1
)
)
.
SELECT
e.[Title],
a.[City],
c.[LastName] + ', ' + c.[FirstName] AS EmployeeName
5>
67
) !
4%
FROM
[HumanResources].[Employee] e
JOIN [HumanResources].[EmployeeAddress] ed ON e.[EmployeeID]
= ed.[EmployeeID]
JOIN [Person].[Address] a ON [ed].[AddressID] = [a].[AddressID]
JOIN [Person].[Contact] c ON e.[ContactID] = c.[ContactID];
"
% .
+ *
7
*
+*
+
%.
.
7
?
8
8
*
0
8&
)
8$
.
+
)
+
*
.!
#&
*
2-7
7
*
7
+
7
27
/% S0
*
)
0
*
'
8$
/ S0
A L
/'4S0
).
(.
*
7
%(+ *
7
5
*
,7& 7.
%#+&%' *
"
#$
=
.
=
*
%#+&%' *
+
.% '%(.
)
&
)
*
+
*
'4S )
7
7. 8
)
3
= )
3
+
+*
)
7
=
))
8
7 9
*
0
)
> +
*
7
%'5
7
)
5>
"
67
) !
4(
#%
!)
*
5
9
?
#. 9
+ *
*
3
) 3
3
* )
)
*.
))
+
+
))
+ 0
)
*)
+
)
+
7
.!
*
)
+
+
1
+
3
.-
.<
+ )
))
8
1
:A
+
*
*
<
/"
7
3
)
* )
* +
)1
)
.
*3
*
" *
7
.A
.9
*
+
+
* )
+
:A
8$
.
)
+
+ 9
?
0
))
.9
?
*
?
))
+
*
)
)
7 .
))
.
1
?
4'
7
/0$ $
/0$ $
*
/
+K
* L
8
))
))
7
1
8 96>6
+
?
1
. )
1
* )
*
0.
3
1
=
*
.
. )
*
+
)
L
))
) *
* 0+
+
.-
. %&
*
8$
3
#
)
7
9
8&
#&
7
?
0
) 9
"
,
-)
6
*
+
+
))
1 .
. %& /
))
)
)
) *+ # . -
8 96>6
7
+
7.
+
9
E +*
&#
2 %4
+
)
@7&
7)
.
*
%4.
7&
2+ *
7
.
?
5>
"
67
4
&
.
8&
) !
44
%4
8$
"7
"
1 +
1
%&.
#)
#
*
>
)
7
.
1
0
.C
7
) *
))
+
1
*
)
/
.7 +
+
7
)1
))
"
*
.
)
)
% +
+*
*
%#.
4&
"
#+
)
)
&
*
85
&
=
)
+ .
)
#
*
3
+ L
*
7 )
*
3
!
1 .
-
"
SELECT
FROM
&
E +
?
3
E + *
)
)
c.CustomerID
Sales.SalesOrderDetail
od
JOIN
Sales.SalesOrderHeader
oh
ON
od.SalesOrderID
=
oh.SalesOrderID
JOIN
Sales.Customer
c
ON oh.CustomerID = c.CustomerID
"
A
)
%$.
#*
=
7
7
4 #
5>
67
/0$ $
*
" 7+
* )
! 1
.
7
1
&
. - ?
+
) 0
)
<
))
7
4$
)
4 #
0
*
E +
E
*
*)
?
4 #
&
2<.
.-?
E
))
*
) 1
1
) +
)
9
E .
3
=
1
1
*
% +*
1
+
1
+
*
3
?
+*
=
E +
AB
?
9
.
E
?
1
E + *
)
+
E +
) !
) ?
3
* )
*
+
. -
E
=
1
+
) *
*
1
?
E
))
. )
)
*
7 .
)
1
?
+
*
<
(
)3
5R
3
>
)
3
/0$ $
* 3
*
+
7
*
/0$ $
.
* *
)
.8 L
8
+
7
.
+
SELECT
e.[Title],
a.[City],
c.[LastName] + ',' + c.[FirstName] AS EmployeeName
FROM
[HumanResources].[Employee] e
JOIN [HumanResources].[EmployeeAddress] ed ON e.[EmployeeID] =
ed.[EmployeeID]
JOIN [Person].[Address] a ON [ed].[AddressID] = [a].[AddressID]
JOIN [Person].[Contact] c ON e.[ContactID] = c.[ContactID]
WHERE
e.[Title] = 'Production Technician - WC20' ;
"
+*
=
7
) *
)
)
/0$ $
+*
&#
/0$ $
*
%4
/ )
%0.
5>
"
67
) !
4#
=+
+*
*
8
7
3
=
+
*
* 1
*
*
7
0
8$
#
./0$ $
)
*
/0$ $
3
K
1
*
+
3
1 .
+
)
1
)
+
)
7
*
*
3
)
*
)
*
*
.
))
+
K*
8&
))
= *
1 .
)
/0$ $
.
+ *
*
*
:A *
+
/0$ $
+
)
.%% ' 4.
.
7
= )
.'
*
*
+ *
3
4 )
&
3
.
*
L )
.E
4
8
7
($' &:
$(
3
( &:
))
*
SELECT
FROM
<$
*
[Production].[ProductInventory]
ORDER BY [Shelf]
"
&#
7
)
/ )
%4
+
=
+
(
4
) *
*
)
*0.
7
+
.
.
. )
)
)
*
<$
)
5>
"
67
&%
*
% &#
7
"
) !
*)
*.
+
/
% &#
'0+
L
% &#
* )
.
$&S )
*
)
7
.
.
&
7
*
)
+
*
.?
9 * +
*
+
3
) /0$ $
3
<
) *
5*
; )
.
L
)
)
/0$ $
.
)
.
*
7 +
) *
4 S ) 3
= .
7
*
+
*
7.
*
)*
)*
SELECT
FROM
;
;
*
[Production].[ProductInventory]
ORDER BY [ProductID]
"
45
&
3
L
+*
3
7
+
<$
*
+*
+
7.
+
)
+
.
:A
+ :A
>-?
)
)
.
+ :A
*
8
=
. )
4
8
)
.!
. 8
+
+
)
4
)
+
+ :A
+*
)
) . )
+
)
>-?
6
?
+*
*
3
&
*
36
) 1
3
.
. A L
5
5>
67
) !
&(
SELECT
[City],
COUNT([City]) AS CityCount
FROM
[Person].[Address]
GROUP BY [City]
"
*.
3
.
=
"
*
*
*
7
+
/0$ $
)
*.
)
3
& 36
*)
+
9
?
7
.
)
9
?
*
1 + 9
?
*
+*
)
*
.
)
9
*
K
1 .-
?
K
:A
) *
.K <
.
:
) +
K
K
/0$ $
)
)*
*
)
7
) *
.
7
SELECT
[City],
COUNT([City]) AS CityCount
FROM
[Person].[Address]
GROUP BY [City]
HAVING COUNT([City]) > 1
*
+
0 =23
.-
$5
&'
"
0 =23
#
%. <
7
)
)
0 =23
)
) *
.8
+& +
.8
4$4
L (' .
"
0 =23
)
3
)
)
) 3
3
/0$ $
.
( #
( 4
8
0 =23
.- *
+
)
*
*
) *
"
>
>*
6
6
>
>*
+
7
*
)
+
= +
.
*
+
*
+*
+ *
<>
. 8
+
5>
67
) !
=
2 (+
&4
/
3 % (+
3 % (+
.
)
+
.-
.-
.,
.
)
)
&# (+
+
) * .
&# (+
2 (+
))
2 (+
)
*
. -
) 1
)
*
.8
.!
*
)
+
*
)
"
>
>*
*
+
7
5
+ )
7
:
*
$%
3
*
4
*
*
$+ *
?
6
=
*
)
+
*
+1
.
= .
.
=
.-
*
*
3
<"
*
*
*
)
3
,!-;
)
+
)
Q<. )
+
+
3
= +
"<
1
) *
*
*
. )
)
*
)
*
)
*
*
*
)
2 (+
*
1 . )
)
) 1
+
=
*
7
+ *
L.8
+
*
&&
7 +
))
.
)*
Q<
;'"
67
)
)
3
*
3
) 4$5$&6 3
+
234$ 6+
< 6$+
<$5$6$ 3
)
L
* *
.8
7
7
,
9
234$ 6
INSERT
VALUES
INTO [AdventureWorks].[Person].[Address]
(
[AddressLine1],
[AddressLine2],
[City],
[StateProvinceID],
[PostalCode],
[rowguid],
[ModifiedDate]
)
(
'1313 Mockingbird Lane',
'Basement',
'Springfield',
'79',
'02134',
NEWID(),
GETDATE()
) ;
/
*
"
0+
))+
4
+ L
.
*. "
) +
)+ *
.
*
)
*
.
!
)
* +*
) *
)
&
3
))
&
#.
*
*
$6< 6$ )
.- )
1
)
)
+
8
84
3
5
1 + *
84
'
.
7 *
4 #
*
*
)
)
+*
)
+
&#
2
= ."
' 2.
)
&#
*
+*
)
)
%2
)
2
7
%4
" 6>
+*
" 6>
+
)
5>
)
7
67
) !
)4
*
7 .
&$
'
2.
+
.)67 % %' 3
1
)
= .<+
8
84
R
*
*
)
84
'
*
+
' 2
)
'"
)
UPDATE
SET
WHERE
[Person].[Address]
[City] = 'Munro',
[ModifiedDate] = GETDATE()
[City] = 'Monroe' ;
"
*5
A L
7
7
+*
+
+)
7
* /0$ $ C& DE
)
7
).
* )
)
.
7+
)
))
)
.
7
+ )
5 )
6 .
.
< 6$ 3
6
$ !
1
/
3
)
6
4$5$&6
+ ) *
.
4
)
#/ )
*
+ )
7
3
+ *
*
+*
$6< 6$(+ )
3
)
) .
+
< 6$
*
.
7
+
)
) +*
< 6$
0.
0.
< 6$
+
)
.A
) "
" **
/*
7
+
)
+
4$5$&6
< 6$ 7
+
)
7C
7.
.
:AA
6
.
+*
&
)
+
.
))
)
< 6$.
DELETE
WHERE
<$5$6$
.
*
)
*
*
Q<
*
+*
)
)
3
FROM [Person].[Address]
[AddressID] = 52;
(%
"
)
7
) 7
)
$#
))
*
3
1 *
.>
*+
.-
*+
)
+
)
*
*
))
<$5$6$
)
4$5$&6
.
+
+*
)
)
&#
7,
.
*.
6 < #
%4
)
)
* 5
Prefix:
[AdventureWorks].[Person].[Address].AddressID
Operator(CONVERT_IMPLICIT(int,[@1],0)).
+ *
+ F A+ *
+
L
)
;
)
Scalar
2. ) L
+ 4 . 8
=
)
.
5>
"
67
&#
-)
+
)"
1
+
*L
<$5$6$
"
) !
$$
)
7
A
E
) 1
.6
)
+
. )
.
7
.
*
)
*
.
A)
3
+
.
)
+
)
E +
) )
+
7 . )
*
+
+
!
1
9 *
)
)
3
1
=
)) . !
.A
*
7
=+
+ *
.
=
+
= 7
+
* )
7 )7
)
)
L 7
(5
(<
.
@?A67
) !
/+
/ %
$%
/ ' ,$%
$( &
' (,
)
*
@?A 7
*
.
L
+
) :A
7
*
+
7
7
)
$+
+ @?A
*
)
)
7 7
:A
)
@?A
:A
4.
= )
7
))
) )
*
*
)
.
+
) .
*
+ @?A
7
+
))
) .
3
)
7
. )
L
))
?
+
"
@?A
= .
7 7
)
)
* . )
*
*
:A
))
7
)
@?A
) )
.<
) :A
+
+
)
).
4
+
+ )
+*
:A
+* L
:A
))
.?
. @?A
L
+
FROM
WHERE
*
7
7
* .
SELECT
* +
*
A
7
@?A
.
@?A
)
6
+ @?A
7
7
)
) * ,!-+
+
A L
+
.8
7
.
@?A 7
)
,!- *
7
@?A 7
ContactID,
LastName,
Phone
Person.Contact
EmailAddress LIKE 'sab%'
))
"
" *+ * L
*
*
7
7
.>
40 / 5 37 55
. "
:A
)
40 / 5 37 55 ))
5
SET SHOWPLAN_ALL ON ;
GO
SELECT
ContactID,
LastName,
Phone
Person.Contact
EmailAddress LIKE 'sab%'
FROM
WHERE
GO
"
> *%
:A
+
*
6
"
4 6%
. )
7)
L )
+*
*
0.
4
) :A
5 37 /.
6%
4
A
5 "
C
7
* 7
5 37
-3
)
6%
+
)
L
3
))
/6A6
+
*
7
)
)* )
.
)
1 +
K
+ *
/G0
* ) ? +
* )
7 7
>
.
.8
G>
7+
(5
@?A67
) !
2<
+
.8
7
7
)
*
.! 7
7
$(
+*
+
?
+
)
.
*+ *
6%
,
)
.
* ( /"
/
8&
)
*
+
(0 *
!
7
0*
OBJECT:([AdventureWorks].[Person].[Contact].[IX_Contact_EmailAddress]),
SEEK:([AdventureWorks].[Person].[Contact].[EmailAddress] >= N'sab' AND
[AdventureWorks].[Person].[Contact].[EmailAddress] < N'saC'),
WHERE:([AdventureWorks].[Person].[Contact].[EmailAddress] like N'sab%') ORDERED
FORWARD
<
=#
5 37
.
3
6A6
8 96>6
0+
[AdventureWorks].[Person].[Contact].[ContactID],
[AdventureWorks].[Person].[Contact].[EmailAddress]
<
3
3
+
/
0
) , ) B
7
.
=
$
%#.
" 7 *
8&
.
)
.
+ ) +
4 6%
3
)
.
(+
*.
' /"
, 40+ *
*
+
.8
7
*
* *
+
*
|--Clustered Index
Seek(OBJECT:([AdventureWorks].[Person].[Contact].[PK_Contact_ContactID]),
SEEK:([AdventureWorks].[Person].[Contact].[ContactID]=[AdventureWorks].[Person].[
Contact].[ContactID]) LOOKUP ORDERED FORWARD)
"
9 *
+ )
+)
7
+$
%#.
$
. )
A C <
)
)
+
*
3
) 7
/"
, 0*
*
)
" +
&
2<+ 5
)
6 &
* * L
)
)
"
3
+
)
.
*
$
)
+
3
:+ $
)
.
2 +
"
7
)
*
.= .
1
=#
5
*.
7
) D
*
"
#4
+
7
+
*
% .
%
L
$%
<
$%
3 .
)
73
+
* 3 +
!
3
3
) *
7 .A L
)1
/0$ $
.9 *
6
5
+*
7
$'
SET SHOWPLAN_ALL ON ;
GO
SELECT
c.[LastName],
a.[City],
cu.[AccountNumber],
st.[Name] AS TerritoryName
[Person].[Contact] c
JOIN [Sales].[Individual] i ON c.[ContactID] = i.[ContactID]
JOIN [Sales].[CustomerAddress] ca ON i.[CustomerID] =
ca.[CustomerID]
JOIN Person.Address a ON [ca].[AddressID] = [a].[AddressID]
JOIN [Sales].Customer cu ON cu.[CustomerID] = i.[CustomerID]
JOIN [Sales].[SalesTerritory] st ON [cu].[TerritoryID]
= [st].[TerritoryID]
st.[Name] = 'Northeast'
AND a.[StateProvinceID] = 55 ;
FROM
WHERE
GO
"
7
7)
+
)
'
*
+
)
).
2-7
"
/G0
)
74
'
+*
.
&
/0$ $
) *
.
--Index Seek(
OBJECT:([AdventureWorks].[Person].[Address].[IX_Address_StateProvinceID] AS [a]),
SEEK:([a].[StateProvinceID]=(55)) ORDERED FORWARD)
(5
@?A67
) !
$4
2+
)
) *
7
)
3
*.
3
4$5$&6
*
7+
2 )
.-
6%
.
/ * 0.
"
*
3
@7&
* )
+
7 :!
*+ *
* %%+ *
)
&
7+
--Index Scan(
OBJECT:([AdventureWorks].[Sales].[CustomerAddress].[AK_CustomerAddress_rowguid]
AS [ca]))
%#+
1
"
*
&
+ 9
* )
)
/ * % 0. )*
7
+*
L
?
+*
7&
)
)
*
+*
)
7&
2.
*
"
$&
"
+*
)
.
"
*
7
+
@72
+
)
)
*
> *'
/G0
'
#7&
2.
* +
> * %4+ *
"
7
8&
) *
7
"
+
*'
1 .
> * (+ *
* %4
"
A
"
1
A
(5
"
@?A67
) !
$$
##
*
4 # 84 # 6
"
A
1
*
.
3
> * %&+ *
)
+*
)
)
+
7
)
)
)
.
-
)+
7
3
=
)
+
. A
)
+ *
*
3
.8
* 7
*
L
)
7
/+
L
)
)
.9 * +
K) )
K)
.
*
+
7
,!- *
:A
+
*
7
:A
4+ *
) )
,!-
*
)*
.9
=+
.
*
8=
)
,!)
*
=
+
)
,
*
+
)+
K
K.
$+ *
.
)
+*
)@?A
+
6
+
3
@?A
7 .
,!- * L
)
+
@?A
3
7
*
@?A
+ @?A
7
/ *
*
+
)
+ @?A
)
3 +
0+
@?A
+
3
*
7
*
7
@?A
+
*
)
+*
/+
+
L
7
7
*
+
*
8
7
40 / 5 37- 5
@?A )
/
7
0. 8
7
3
40 / 5 37- 5
3
)
*
SET SHOWPLAN_XML ON ;
GO
SELECT
FROM
WHERE
c.[LastName],
a.[City],
cu.[AccountNumber],
st.[Name] AS TerritoryName
[Person].[Contact] c
JOIN [Sales].[Individual] i ON c.[ContactID] = i.[ContactID]
JOIN [Sales].[CustomerAddress] ca ON i.[CustomerID] =
ca.[CustomerID]
JOIN Person.Address a ON [ca].[AddressID] = [a].[AddressID]
JOIN [Sales].Customer cu ON cu.[CustomerID] = i.[CustomerID]
JOIN [Sales].[SalesTerritory] st ON [cu].[TerritoryID] =
[st].[TerritoryID]
st.[Name] = 'Northeast'
AND a.[StateProvinceID] = 55 ;
GO
SET SHOWPLAN_XML OFF ;
@?A
(5
"
@?A67
) !
$#
)
@?A ) . @?A
+*
*
)
+
))
KUK
KK
.
-
* )
5QQ
)
.
)
).
)
-)
)
%0+
)
4
Q3
Q 'Q $Q
* @?A
* *
.#
+4
Q.
#
) ?
/
# 5
= )
.
" 7
)
+ *
!2
7
= .8
)+
8=
+ *
6
)
7 .
*
F *
7
7
% .
@?A+
*
@?A
%+ *
@?A ) :
)
@?A
+
)
*
*
@?A
. I 7 I3
)
I
) .
.
<MissingIndexes>
<MissingIndexGroup Impact="30.8535">
<MissingIndex Database="[AdventureWorks]" Schema="[Sales]"
Table="[CustomerAddress]">
<ColumnGroup Usage="EQUALITY">
<Column Name="[AddressID]" ColumnId="2" />
</ColumnGroup>
<ColumnGroup Usage="INCLUDE">
<Column Name="[CustomerID]" ColumnId="1" />
</ColumnGroup>
</MissingIndex>
</MissingIndexGroup>
</MissingIndexes>
)
2 E*+ )
> <
=.
)
+*
$
)
. "
+
@?A
$%
)
)
)
7
7
1
1
*
)
)*
*
+ *
*)
.
*
+ ) "
V &+
"
V +*
5
"
>
& #
"
+*
* K6
67
V%4. '#%&K.
<OutputList>
<ColumnReference Database="[AdventureWorks]" Schema="[Person]"
Table="[Contact]" Alias="[c]" Column="LastName" />
<ColumnReference Database="[AdventureWorks]" Schema="[Person]"
Table="[Address]" Alias="[a]" Column="City" />
<ColumnReference Table="[cu]" Column="AccountNumber" ComputedColumn="1" />
<ColumnReference Database="[AdventureWorks]" Schema="[Sales]"
Table="[SalesTerritory]" Alias="[st]" Column="Name" />
</OutputList>
/
"
@?A
3 .
K
K K0+
0.
*
+
)
K /
K K0+ K3
)
*
*
*.
)
K /
K K0
/A "
+
K
K
+-
"
*
K
K
(5
@?A67
) "
) !
+*
+
%
)
"
<NestedLoops Optimized="0">
<OuterReferences>
<ColumnReference Database="[AdventureWorks]" Schema="[Sales]" Table="[Customer]"
Alias="[cu]" Column="TerritoryID" />
</OuterReferences>
/+
8
)
*.8 * L
@?A
+
))
.
+1
c.[LastName],
a.[City],
cu.[AccountNumber],
st.[Name] AS TerritoryName
[Person].[Contact] c
JOIN [Sales].[Individual] i ON c.[ContactID] = i.[ContactID]
JOIN [Sales].[CustomerAddress] ca ON i.[CustomerID] =
ca.[CustomerID]
JOIN Person.Address a ON [ca].[AddressID] = [a].[AddressID]
JOIN [Sales].Customer cu ON cu.[CustomerID] = i.[CustomerID]
JOIN [Sales].[SalesTerritory] st ON [cu].[TerritoryID] =
[st].[TerritoryID]
st.[Name] = 'Northeast'
AND a.[StateProvinceID] = 55 ;
FROM
WHERE
GO
8
)
< !
)
+ *
###
?
/
)
#
$0
))
)7
)
@?A 7
6
2
)
+
*
)
+
.8
<RunTimeInformation>
<RunTimeCountersPerThread Thread="0" ActualRows="4" ActualEndOfScans="1"
ActualExecutions="1" />
</RunTimeInformation>
<NestedLoops Optimized="0">
!
*
@?A
+
+
),!- *
,!-L * L
*
+
+
*
)
*
@?A )
. )
)
) @?A
.
+ ,!)
.
*
)
@?A
*
7
,!,!-
'5 C
(=
. '%
- *L
*
7:
+$(
% ,%
3
:A
$+
7
. 9 *
+
7
*
*
/ ' (:
*
;
*
7
7
7
+ 1
+
:A
7
.
:A 3
*L
+
7+
.
))
)
-
)7 + ))
L
8
*
-
. 8 L
[st].[SalesTaxRateID],
[st].[Name],
[st].[TaxRate],
[st].[TaxType],
[sp].[Name] AS StateName
FROM
[Sales].[SalesTaxRate] st
JOIN [Person].[StateProvince] sp ON [st].[StateProvinceID]
= [sp].[StateProvinceID]
WHERE
[sp].[CountryRegionCode] = @CountryRegionCode
ORDER BY [StateName]
GO
"
%5
'
)
+*
&#
2 %4
! & +
+ F&
*
*.
4 #6%
5
1 *
)
3
" 7+ *
)
2
+*
4
2
)
5
@7&
)
%4
73
+
4 #6%
1
5
1 )
7)
7.
3
.,
)
%4
.
+
)
.
8
L
.
7+
:A *
4$5$&6
L
*
)*
*.
#
<
)
)
)
*
*
*
4$5$&6
:A
+
#. )
L
4$5$&6
4$5$&6 3 . <
*
+
*
)
.
)3
'
)
+
4$5$&6
L
+ ) *
#
C
4
-
#
8
+
*
.
5
* +* *
)
0
*
+*L
)
SELECT
[p].[Name],
[p].[ProductNumber],
[ph].[ListPrice]
FROM
[Production].[Product] p
INNER JOIN [Production].[ProductListPriceHistory] ph
ON [p].[ProductID] = ph.[ProductID]
AND ph.[StartDate] = ( SELECT TOP ( 1 ) [ph2].[StartDate]
FROM
[Production].[ProductListPriceHistory] ph2
WHERE
[ph2].[ProductID] = [p].[ProductID]
ORDER BY [ph2].[StartDate] DESC
'5 C
7:
"
8
7
*
8
+*
5
.
! 1
?
*
0
)
7
)
3
)
*
+
1 R
*
)
.!
* 0.
*
) *
))
)
7
.
*
3
K.
.-
)
E +*
*
.
+
/7
*
*
+
+
) *
2.
-?
*
.
)
+?
.8
E
) *
.8
.6 .
) 9
*
/ )
*0
&
"
" 7+ *
+
*
(#4
7
) &$S )
3 +
*
* )
.*
)
3
*)
(A+ )
* *
* *
.
.
)
K%.K
#
*
.
*
+
D8C
C
C4
3
6
*
*
6
+
*
)
<
*
5
D
'5
C
+ *
D8C
'5 C
"
*
.
#
" *
*
*L
)
Q
)7
:A
3 +
*
44
)
+ &
* )
)
*
Q %$4%4&.
7
1 *
)
))
*
.
5
*
4
5
SELECT
FROM
*
*
Q
*
"
*
3
:A
)
*
)
7:
)
5
+
*
+*
))
+
*
.
))
+
6$
5 .
)
+
AF
K
+
* )
5
K.
5QQ
).
7.
*
.>
[p].[Name],
[p].[ProductNumber],
[ph].[ListPrice]
[Production].[Product] p
CROSS APPLY ( SELECT TOP ( 1 )
[ph2].[ProductID],
[ph2].[ListPrice]
FROM
[Production].[ProductListPriceHistory] ph2
WHERE
[ph2].[ProductID] = [p].[ProductID]
ORDER BY [ph2].[StartDate] DESC
) ph
*)
45
"
&
+
1
4
3
)
5
6
*
* *
)*
3
4$6 46 62462&4 2
) ?
)
3
))
+*
0
3
;< *
3. 8
3 .
+
%
.
5
)
+ <
)*
)*
+
/$#40
3
)*
*
)
/%
*
/0$ $
0.
)
5
WHERE [p].[ProductID] = '839'
*
&5
/0$ $
+*
'5 C
"
#
&#
+
2
)*
"
))
%4
/
*
)
+
+ *
/0$ $
+*
$5
&#
2 %4
/0$ $
*
+
.
" *+
*.
8
7:
+
7
)
<
4+ *
2 %4
)
&#
+*
)
)
*
+*
(1 row(s) affected)
Table 'ProductListPriceHistory'. Scan count 1, logical reads 4, physical reads 0,
read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead
reads 0.
Table 'Product'. Scan count 0, logical reads 2, physical reads 0, read-ahead
reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
+*
(1 row(s) affected)
Table 'ProductListPriceHistory'. Scan count 1, logical reads 2, physical reads 0,
read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead
reads 0.
Table 'Product'. Scan count 0, logical reads 2, physical reads 0, read-ahead
reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
" *+ *
+
) /0$ $
3
*
+
'
3
.
))
+*
#
)
7
)
*
.
+
! >
+
)
/0$ $
+
5 )
*
)
7
)
))
* *
*
7
.C
.
*
)
+*
/0$ $
. 8
+
))
"
:A
:A
+
*
+*
7
/ 60. 6
:A
.
*
)
:A
*
.C
)
<
:A
*
)
3
)
)
.
K
*
)
))
) )
7
+
.#
'
7
3
.+
!
8
)
*5
Q 3Q 3
6
4Q 3
5
4
5QQ***.
Q.
'5 C
A L
7:
#%
@?A
8
)
.8 * 7
77
@?A
*
.
"
- 3
5
8$
)
)
1
#
3
)
8&
)
7
%4
.
K K
3
+*
&
+
.
&
.
)
5 ' #+
.
)
&#
4 #
32 3
55
:A.
)
"
#5
.
.
.*
.)
6 #
)
+
1
/
3
*
7
.A
) "
+ )
7
)
1
)
32 3
55
)
6.
#
)
"
%#
@?A
<RunTimeInformation>
<RunTimeCountersPerThread Thread="0" ActualRows="4" ActualRebinds="1"
ActualRewinds="0" ActualEndOfScans="1" ActualExecutions="1" />
</RunTimeInformation>
*
+*
R
)
)
"
.
*
*
+*
* *
*
-
% 5
-)
&
*
)
*
+*
*
+ 1
%4
* 1
34
*
/
9
3
*
+* * 1 )
*.
KP
.
+
*
) *
7 )
*
) *
*
+
*L *
+
0.
*
34
*+ 4 # 8'2
)
)
SELECT
FROM
WHERE
'
#&
+
.-
*
[Sales].[vIndividualCustomer]
[CustomerID] = 26131 ;
%%5
'5 C
"
7:
#(
##
8
>
*+ '2
:A
)
*
+
.
)) +
'
#&
+ *
+ *
3
3
*
*
)
=+
1 +
*.
)3
.
7
*
.
1
3
L
*
*
*.
34
-
7 B *+
7
7
*
)
=
+
+
3
*+
*
*
*
+
.
* +
))
*
7
7
7
*
7
*. <
) +
+ )
)
234$ 6 *
)
7
+
*.
234$ 6
*. - ,!-+
* *
*
7
:
)
)
+*
4$5$&6 3
+
!
.
) 3
*
4
)
3
&
*+
.
.
. )
*
*
1
7
+
+ )
*
?
7K.
1
7
K
7
*
'
.
-
8
&
'4
!
'
#'
SELECT
FROM
*
[Person].[vStateProvinceCountryRegion]
"
% 5
7
7
*+
7
7
7
)
7
SELECT
7
.
7
% 5
SELECT
3
*
.
7
a.[City],
v.[StateProvinceName],
v.[CountryRegionName]
[Person].[Address] a
JOIN [Person].[vStateProvinceCountryRegion] v ON
[a].[StateProvinceID] = [v].[StateProvinceID]
[a].[AddressID] = 22701 ;
FROM
WHERE
"
= *
*.
+
.
)
*
= +
)
+ *
*+
sp.[Name] AS [StateProvinceName],
cr.[Name] AS [CountryRegionName]
[Person].[StateProvince] sp
INNER JOIN [Person].[CountryRegion] cr ON
sp.[CountryRegionCode] = cr.[CountryRegionCode] ;
FROM
9 *
#$
)
=
7
)
)
)
=
7 7
*+ *
*
% +
*
'5 C
*.
7:
3
)
#4
*
7
+
*
*.%%
,
-
))
-)3
;K
3
)
7
*
+
3
3
,
<
5
)
+
7
=
)
A
7
<
5
.
=
0+
*+
3
)
* +
:
+
)/ 2<
3
)
7+
.
3
[sod].[ProductID],
[sod].[OrderQty],
[sod].[UnitPrice]
[Sales].[SalesOrderDetail] sod
[sod].[ProductID] = 897
3
)
FROM
WHERE
.- *
+
*
)
)*
*
7
+
/@
3
3
L
)
=.
)
7
+
7
5"
SELECT
.9 *
*
K
A
7)
7 +
-!
)
&
+ !
*+ )
+
3 0.
7+ )
0+
+ :A
))
)
.
)
.
7
+
*
%'+ *
%%
+*
9
*
)
7
4.
"<6@ -",
#&
"
#%
%4
+
C )
"
* *
7
+ 3
2.
))
#&
)
7+
)
4 #
%4+
2
7
4 #
7
D A
?
C +*
= *
8
3
:A
*
#7
7
3
7.
*
<
#2 .
).
=
+)
+
+ 2-74 #
4+ *
7.
)
<
2+
)
)
23&5 <$
7
. 9 *
*
7
+
:A
'5 C
23&5 <$
)
7:
#$
*
.
:A
4
7+ )
)+
7. -
)
+
)
))
3
7
.
7+
)
7+
.
)
7
))*
+*
)
*
*L
.
7
23&5 <$
.
+*
46 62462&4 - 5
+
) *
46 62462&4 - 5
)
)
*
IF EXISTS ( SELECT
FROM
WHERE
*
sys.indexes
OBJECT_ID = OBJECT_ID(N'[Sales].[SalesOrderDetail]')
AND name = N'IX_SalesOrderDetail_ProductID' )
DROP INDEX [IX_SalesOrderDetail_ProductID] ON
[Sales].[SalesOrderDetail]
WITH ( ONLINE = OFF ) ;
CREATE NONCLUSTERED INDEX [IX_SalesOrderDetail_ProductID] ON
[Sales].[SalesOrderDetail] ([ProductID] ASC)
INCLUDE ( [OrderQty], [UnitPrice] ) WITH ( PAD_INDEX = OFF,
STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY
= OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON,
ALLOW_PAGE_LOCKS = ON )
ON [PRIMARY] ;
GO
SET STATISTICS XML ON ;
GO
SELECT
[sod].[ProductID],
[sod].[OrderQty],
[sod].[UnitPrice]
[Sales].[SalesOrderDetail] sod
[sod].[ProductID] = 897 ;
FROM
WHERE
GO
SET STATISTICS XML OFF ;
GO
--Recreate original
IF EXISTS ( SELECT
FROM
WHERE
index
*
sys.indexes
OBJECT_ID = OBJECT_ID(N'[Sales].[SalesOrderDetail]')
AND name = N'IX_SalesOrderDetail_ProductID' )
DROP INDEX [IX_SalesOrderDetail_ProductID] ON
[Sales].[SalesOrderDetail]
WITH ( ONLINE = OFF ) ;
CREATE NONCLUSTERED INDEX [IX_SalesOrderDetail_ProductID] ON
[Sales].[SalesOrderDetail] ([ProductID] ASC)
WITH ( PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF,
SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF,
ONLINE = OFF, ALLOW_ROW_LOCKS = ON,
ALLOW_PAGE_LOCKS = ON ) ON [PRIMARY] ;
GO
EXEC sys.sp_addextendedproperty @name = N'MS_Description',
@value = N'Nonclustered index.', @level0type = N'SCHEMA',
@level0name = N'Sales', @level1type = N'TABLE',
@level1name = N'SalesOrderDetail', @level2type = N'INDEX',
@level2name = N'IX_SalesOrderDetail_ProductID' ;
Run this code in Management Studio with the "Include Actual Execution Plan"
option turned on, and you will see the execution plan shown in Figure 16:
))
.
"
#)
)
7
!
A L
)*
=
+
*
7. -
)
7
.-
+
7+
"
7 .
7 5
*
#*
%+
)
)
#
-
7
7.
' 8
7L
+
)
) *.
+
)
) *
* . -)
7
7
.
)
3
)
7.
=.
7
<
#7
,!
4 # 84 #
<
2<+
2<
+ 40 /746 62462&45
#
.
7+ 2-74 #
7
DBCC SHOW_STATISTICS('Sales.SalesOrderDetail',
'IX_SalesOrderDetail_ProductID')
.C
5
All density
------------0.003759399
8.242868E-06
8.242868E-06
Average Length
-------------4
8
12
Columns
------------------------------------------ProductID
ProductID, SalesOrderID
ProductID, SalesOrderID, SalesOrderDetailID
'5 C
7:
+
.
7
=.
*
. )
.
7
L *
7 3
))
)
.
7
7
L
)
3
0
SELECT
*
+
) . ($4#(##+ *
7. 7
7
L *
)+ )
)
7
+*
)
.A L
)3
) +
). A L
8
)
1 2
L
3
L
.
*
=
)
sod.OrderQty,
sod.[SalesOrderID],
sod.[SalesOrderDetailID],
sod.[LineTotal]
[Sales].[SalesOrderDetail] sod
sod.[OrderQty] = 10
FROM
WHERE
"
##
%4
+*
% 5
&#
)
A L
#
?
E A*.
C )
+ )
% R
+
*
+
* +
)+
40 /746 62462&45
7
7
*
.
*
*
*
7
< &&
All density
Average Length Columns
------------- -------------- ------------------------------------------0.02439024
2
OrderQty
2.18055E-05
6
OrderQty, SalesOrderID
8.242868E-06
10
OrderQty, SalesOrderID, SalesOrderDetailID
8
+
)
?
?
7
% %(%$ *
4 #
)
?
.
))
3
.
2
3
.
<
#
1
L+
.
)+
+
)
'%
7
%
)*
* +
=.F
+
)
7*
/
+
* *
+
40. >
=
L
)
7+
+
)
7
)
L )
5
)
*
7
L *
7*
,
)
."
))
))
))
*
+
.
)
*
+
3
+
*+
))
75
IF EXISTS ( SELECT
FROM
WHERE
*
sys.objects
object_id = OBJECT_ID(N'[NewOrders]')
AND type in ( N'U' ) )
DROP TABLE [NewOrders]
GO
SELECT *
INTO
NewOrders
FROM
Sales.SalesOrderDetail
GO
CREATE INDEX IX_NewOrders_ProductID on NewOrders ( ProductID )
GO
/ ?@A )
+
-- Estimated Plan
SET SHOWPLAN_XML ON
GO
SELECT [OrderQty]
,[CarrierTrackingNumber]
FROM
NewOrders
WHERE
[ProductID] = 897
GO
SET SHOWPLAN_XML OFF
GO
BEGIN TRAN
UPDATE NewOrders
SET
[ProductID] = 897
WHERE
[ProductID] between 800 and 900
GO
-- Actual Plan
SET STATISTICS XML ON
GO
SELECT [OrderQty]
,[CarrierTrackingNumber]
FROM
NewOrders
WHERE
[ProductID] = 897
0. -)
3 +
3
7
'5 C
7:
% %
ROLLBACK TRAN
GO
SET STATISTICS XML OFF
GO
@?A
%0+
!
*
32
) :A
@?A
"
)
*
#+
"
%#
+
.
7
)+
*
7*
4$5$&6
3
2< 5
)
9 * + )
+
*
+
. '(( % *
*
+
)
)
+
.
*.
3
7+
.
%. '('. "
!
7
7
*+
*
* )
* +*
)
)+
.
)
* )
+
.
+
)
*
7
.
7
%
L
.F
F
7 +
)
)
45
67
(>
. $% ($
,%
% (
/ ' ,$%
% *,
,%
+
0
3 .
1 0
6 #0
=
=
L
)
7
1
)
*
3
3
7)
5
.
*
+
)
.-
3
3
.
)
!:
!. 8
3
)
.
+
L
)
)
+ L
)
7
*
!
3
)3
)*
) ))
62 3
.
.
*5
SELECT ...
OPTION (<hint>,<hint>...)
234$ 6
.F
!)
*
.
4$5$&6
?$(
( ($'
*
P 0 40
/ *
<$
<24623&6
&
=
7
**
P
6$
+
3
L
) ))7
0.
.
)3
SELECT
[c].[Suffix],
COUNT([c].[Suffix]) AS SuffixUsageCount
FROM
[Person].[Contact] c
GROUP BY [Suffix]
3
*
)3
)
)
L
)
% '
)
*
"
+ )
+
7
K ) K
=
*
.
9
?
)
/-
.
7
)
.
.4#
$+ *
"
)
9
<$
SELECT
[c].[Suffix],
COUNT([c].[Suffix]) AS SuffixUsageCount
FROM
[Person].[Contact] c
GROUP BY [Suffix]
OPTION ( ORDER GROUP )
"
%5
(5
+
)
3
45
67
8 L
% 4
=
)
!! !
-
+*
*
)%.$$$'4 ) +
+
+ L
*
).4#
)
.
)
+ (
=
:
+
) +
=+
=
7.
? $%
7
)
*
9
6
)
*
.8
L
+
.
+
?
=
3
))
'%,$%
* C" <"
+
*
*
) *
C" <"
7
+
)
))
=
$
.
<$
)
3
)
*
)
.
+
.
))
5
SELECT
FROM
UNION
SELECT
FROM
"
[pm1].[Name],
[pm1].[ModifiedDate]
[Production].[ProductModel] pm1
[pm2].[Name],
[pm2].[ModifiedDate]
[Production].[ProductModel] pm2
F
7 )
+
)
+
. ($$.
)
)
SELECT
FROM
UNION
SELECT
FROM
OPTION
)
$
32 3
[pm1].[Name],
[pm1].[ModifiedDate]
[Production].[ProductModel] pm1
[pm2].[Name],
[pm2].[ModifiedDate]
[Production].[ProductModel] pm2
( MERGE UNION )
C" <"
5
=
*
+
7
*
))
% &
"
&
F
&
*L
)
)
)
32 3
.9 * +
=
. 4' .
. ($$
* 4
.
L *
+ 0 40
SELECT
)
)
3
.9 *
32 35
[pm1].[Name],
[pm1].[ModifiedDate]
[Production].[ProductModel] pm1
FROM
UNION
SELECT
[pm2].[Name],
[pm2].[ModifiedDate]
[Production].[ProductModel] pm2
( HASH UNION )
FROM
OPTION
* 7
"
! 1
*
*
&5
) +*
/. '#$0
)
3 +
9
+)
))
.
+
*
)
$$ ?+ (
9 *
F L
.
) 1 +
0
3
))
3
)
3
)
.
7
$,%
1
) 1
1
L
7
)
)
5
Q<+
)
.!
* 3
)
*
.9
45
SELECT
% $
s.[Name] AS StoreName,
ct.[Name] AS ContactTypeName,
c.[LastName] + ', ' + c.[LastName]
[Sales].[Store] s
JOIN [Sales].[StoreContact] sc
ON [s].[CustomerID] = [sc].[CustomerID]
JOIN [Person].[Contact] c
ON [sc].[ContactID] = [c].[ContactID]
JOIN [Person].[ContactType] ct
ON [sc].[ContactTypeID] = [ct].[ContactTypeID]
FROM
"
67
+
3
.A L
+ ?
G?
<K
7.
Table
Table
Table
Table
Table
Table
Table
Q<
7 )3
)
+
5
3
0
.
+
*
E
E
&
3 .
*
*
) 3 5
"
9
A
%
" *
+
9 *
1 .
3
7
) *
+
)
+
+*
Table
Table
Table
Table
Table
Table
"
*
3
. )
L
.8
)
)
+
+*
3
)
3
%$
))
%'
*
*L
$
+
.8
)
$ 1 23
)
)
5
)* *
) 3
"
7
Table
Table
Table
Table
Table
Table
Table
8 L
.8
*
3
)
.9 *
0 40 1 23
5
OPTION ( HASH JOIN )
)
*
*
.?
7
)
+*
)
45
"
67
% #
8 L
*
Table
Table
Table
Table
Table
Table
Table
9
Q<
7
Q<
+
3
+ *L
)
)
*
+
)
46
7
)
L L
)
.
SELECT
FROM
"
*
3
)
)
) L
.
.
.
+ *L
*
+
=
+*
5
)
*
)
L L
*
[Sales].[SalesOrderDetail] sod
JOIN [Sales].[SalesOrderHeader] soh
ON [sod].[SalesOrderID] = [soh].[SalesOrderID]
##
3
*
)
)7
OPTION
( FAST 10 )
)
) %
+
5
%%
"
*
*
* .
)
*
)
3 .
)
. % /)
) %
* 0.
3
% %+ $ )
3
+)
)
*
)
.
)
$(
$(
F L
SELECT
+% ( )
7
)
* *
*
+
.
*
)
.
))
*
*
)
)
)
)
= *
*
))
* %.#$(.
3
)
3 +
'.
+
<$
).
*
3
+)
)
."
&$
3
) +
*
1 23
*
5
FROM
1 +
)
*
+*
7 .9
=
)
=.
)) O
1
)1
)
)*
1
=
)
pc.[Name] ProductCategoryName,
psc.[Name] ProductSubCategoryName,
p.[Name] ProductName,
pd.[Description],
pm.[Name] ProductModelName,
c.[Name] CultureName,
d.[FileName],
pri.[Quantity],
pr.[Rating],
pr.[Comments]
[Production].[Product] p
LEFT JOIN [Production].[ProductModel] pm
ON [p].[ProductModelID] = [pm].[ProductModelID]
LEFT JOIN [Production].[ProductDocument] pdo
ON p.[ProductID] = pdo.[ProductID]
LEFT JOIN [Production].[ProductSubcategory] psc
ON [p].[ProductSubcategoryID] = [psc].[ProductSubcategoryID]
LEFT JOIN [Production].[ProductInventory] pri
ON p.[ProductID] = pri.[ProductID]
LEFT JOIN [Production].[ProductReview] pr
ON p.[ProductID] = pr.[ProductID]
LEFT JOIN [Production].[Document] d
ON pdo.[DocumentID] = d.[DocumentID]
LEFT JOIN [Production].[ProductCategory] pc
ON [pc].[ProductCategoryID] = [psc].[ProductCategoryID]
LEFT JOIN [Production].[ProductModelProductDescriptionCulture]
pmpd ON pmpd.[ProductModelID] = pm.[ProductModelID]
LEFT JOIN [Production].[ProductDescription] pd
ON pmpd.[ProductDescriptionID] = pd.[ProductDescriptionID]
LEFT JOIN [Production].[Culture] c
ON c.[CultureID] = pmpd.[CultureID]
45
67
.9
"
%%%
)
7 5
<
) )
*
.
.4 4(.
3
&$
<$ 3
"
%'.
%'R
)
6A6
7
)
%(. . C )
=.
))
%.%&$&.
)
*
+
)
)
)
+*L
7
)
3
))
*
1
+ /$
F
)
* .F
7
*
)
.
+
7
1
+
+*
3
:A
.F
3
) +
)
)
5
%%
"
&
*+
* /
05
"
*
)
+
))
)
).
-<
*
0
)
)).
3
*
L *
)
)K? 7,
*
)
*
)
-<
3
K.
+ L
5
wo.[DueDate],
MIN(wo.[OrderQty]) MinOrderQty,
MIN(wo.[StockedQty]) MinStockedQty,
MIN(wo.[ScrappedQty]) MinScrappedQty,
MAX(wo.[OrderQty]) MaxOrderQty,
MAX(wo.[StockedQty]) MaxStockedQty,
MAX(wo.[ScrappedQty]) MaxScrappedQty
FROM
[Production].[WorkOrder] wo
GROUP BY wo.[DueDate]
ORDER BY wo.[DueDate]
GO
sp_configure 'cost threshold for parallelism', 5 ;
GO
RECONFIGURE WITH OVERRIDE ;
GO
*
)
7
%&
)
?
/U0
9 *
+*
.
&#
.
. *
.
*
)
2
7
#3
*
*
+
)
.A
%4
))
+
)
))
)+
5
* .8
*
45
67
%%(
SELECT
wo.[DueDate],
MIN(wo.[OrderQty]) MinOrderQty,
MIN(wo.[StockedQty]) MinStockedQty,
MIN(wo.[ScrappedQty]) MinScrappedQty,
MAX(wo.[OrderQty]) MaxOrderQty,
MAX(wo.[StockedQty]) MaxStockedQty,
MAX(wo.[ScrappedQty]) MaxScrappedQty
FROM
[Production].[WorkOrder] wo
GROUP BY wo.[DueDate]
ORDER BY wo.[DueDate]
OPTION ( MAXDOP 1 )
* 7
/. . *
)) 05
"
+
&#
L )
2
%4
.
)
)
)
4
.
)
* *
)
. 8
4 #
)
)
1
+
)
=
+ L
,+,@ $(
F
*
7
3
. 8
+
7
)
+
)
+
+
)
*
+*
* .
)
.
62 2G$
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3
)
+ @$$
2-$<
@$$
5 3
5 3+
:A
.
C
)
= +
- *
)
.
@$$
.
3
5 3+
3
*
. )
)
)
.
)
7
+)
/ % 3, *
F
*
.
= +
7 +
.<
.<
.
)
+
3
)
*
+
.9 *
7
*
+ )
))
3
7
7
*
* *
3
7
*
*0
*
)
*
3
* *
*
L
.
=
3
)
+*
)
.
*
*
+
3< =2$/4 3
=
)
)
*
* )
/
*
*.
/260 (3 $- 3<+
*
*
.
$)
L
3
*
+
)
)
7
*. 8
.
+
45
67
)
)
)
SELECT
FROM
7
3
+*
62 3 ($-
7+
7
3< =2$/4++
. )*
'5
7. 8
&#
*
84
!
4
.
'
<
.
*
1
'
). ' %
' +
)
= +
% 4
7
)
)
7
* *
=
*.
'( ,$%
8
)
)
3
67
*
*
)
B
*
)
)
7
L
.
3
- $&
:A
42 3
( +$&$.
% .8
.
*
7
=
+
* )
+
.
.C
7
'
" ** L
7
8&
! 1 + )
) 3
+ /(
"
%%#
*
[Person].[vStateProvinceCountryRegion]
"
%
=
*
*
.
@?A
7
->
*L
:A
+
3
) 3
> 5
/K
*)
K0
*
)
.
! > 5
)
0
1
> 5
+
+
) *.>3
* )
/K
K0
)
1
.
.B
))
)
.
3 1
. 6))
*+
)
) )
)
3
)
)
:A
))
.E
.
/
.
?
= L
1
1
+
.,
*.?
*
)
+
0*
SELECT
[pm].[Name],
[pm].[CatalogDescription],
p.[Name] AS ProductName,
i.[Diagram]
FROM
[Production].[ProductModel] pm
LEFT JOIN [Production].[Product] p
ON [pm].[ProductModelID] = [p].[ProductModelID]
LEFT JOIN [Production].[ProductModelIllustration] pmi
ON [pm].[ProductModelID] = [pmi].[ProductModelID]
LEFT JOIN [Production].[Illustration] i
ON [pmi].[IllustrationID] = [i].[IllustrationID]
WHERE
[pm].[Name] LIKE '%Mountain%'
ORDER BY [pm].[Name] ;
8 L
)
1
. )
))
.
>
1
7
1 +
)
* * L
)
.
45
"
67
% %
&
)
H
3
) *
H
7
1
L
. <
.
0
1
52@$
7R
#
'&S )
+
+
.
)
4
<$
*
1
7
#2##
*
*
/0$ $
* L
&#
2
*
% 4
A
2##
1
)
. #' $.
8
"
5
)*
A
1
1
*L
)
=
9
*
1 ;8
)
#5
SELECT
[pm].[Name],
[pm].[CatalogDescription],
p.[Name] AS ProductName,
i.[Diagram]
FROM
[Production].[ProductModel] pm
LEFT LOOP JOIN [Production].[Product] p
ON [pm].[ProductModelID] = [p].[ProductModelID]
LEFT JOIN [Production].[ProductModelIllustration] pmi
ON [pm].[ProductModelID] = [pmi].[ProductModelID]
LEFT JOIN [Production].[Illustration] i
ON [pmi].[IllustrationID] = [i].[IllustrationID]
WHERE
[pm].[Name] LIKE '%Mountain%'
ORDER BY [pm].[Name] ;
)* 7
"
*3
+*L
+*
.- +
+*
* 9
)
+*
)
. -
"
"
)
A
1
.
) 4&S )
A
A
+
%
*
'&S. -
) .%& ('.
)
"
"
. $&'$+
E
)
))
+*
9
)
?
)
*
+
)
).
Q<
"
)
)
+*
3
3
)
Original (Hash)
Table 'Illustration'. Scan count 1, logical reads 273
Table 'ProductModelIllustration'. Scan count 1, logical reads 183
Table 'Worktable'. Scan count 0, logical reads 0
Table 'ProductModel'. Scan count 1, logical reads 14
Table 'Product'. Scan count 1, logical reads 15
Loop
Table 'Illustration'. Scan count 1, logical reads 273
Table 'ProductModelIllustration'. Scan count 1, logical reads 183
Table 'Product'. Scan count 1, logical reads 555
Table 'ProductModel'. Scan count 1, logical reads 14
Merge
Table 'Illustration'. Scan count 1, logical reads 273
Table 'ProductModelIllustration'. Scan count 1, logical reads 183
Table 'Product'. Scan count 1, logical reads 15
Table 'ProductModel'. Scan count 1, logical reads 14
3
9
9
9
.
7
1
+ L
*L
*
?
1 +
+
7
1 .
*
3
)
*
*
) %4 )
+
*
?
1 .
.!
+
*
+
))
1 + 444
))
+
3 .
*
=
*
)
)
) .
) +
1 *
)
*
*
.
#
)
7
7
- *
*
7
*
1
= K
*
)
.
+
)
=
))
45
67
+
)
L ))
!
% (
))
+* * L
7
*
:A
.
*
<
.
.
4.
!
7
:A
/260
/260
*
*
/260
/260
)
*
. 6
+
+
%$ / %
8
7
*
*
$)
)
*
:A
46
)
*
3< =2$/4 3
K 7
K
*
)
)
3 $- 3<
7
* *
* )
.
*
)
7
*
)
7*
.
7
3
.
7
* )
7
*
.
5
-" I"CAA
-" I8->" "
<" - I"CAAIF 6A, I"CAA
-" I -,, "
-> 9-!<>
:C< 6,I ,6"
6>
"C?6> I><C",-!<>
))
3 $- 3<
'+ *
'4
' &
* *
7
3 $- 3<
SELECT
)
3
!
I )
=
)
8
(
.
1 . 8
7)
)
= 7
7
7
a.[City],
v.[StateProvinceName],
v.[CountryRegionName]
FROM
[Person].[Address] a
JOIN [Person].[vStateProvinceCountryRegion] v WITH ( NOEXPAND )
ON [a].[StateProvinceID] = [v].[StateProvinceID]
WHERE
[a].[AddressID] = 22701 ;
Now, instead of a 3- table join, we get the following execution plan:
*.
B *+
*
% '
"
" *+
)
,%
*
+*
)
)
. # 4
*+
*L
. &4$.
/8
9
%(+
7
7
7+
)
*
*
.
+
7+ )
7 5
9 *
*
05
7*
F
*
A L
SELECT
FROM
WHERE
.
3
"
[de].[Name],
[e].[Title],
[c].[LastName] + ', ' + [c].[FirstName]
[HumanResources].[Department] de
JOIN [HumanResources].[EmployeeDepartmentHistory] edh
ON [de].[DepartmentID] = [edh].[DepartmentID]
JOIN [HumanResources].[Employee] e
ON [edh].[EmployeeID] = [e].[EmployeeID]
JOIN [Person].[Contact] c
ON [e].[ContactID] = [c].[ContactID]
[de].[Name] LIKE 'P%'
"
45
"
67
% 4
8
A
7
*
*L
7
L
23<$SELECT
)*
8<
7<
2<. 8
[de].[Name],
[e].[Title],
[c].[LastName] + ', ' + [c].[FirstName]
[HumanResources].[Department] de
WITH ( INDEX ( PK_Department_DepartmentID ) )
JOIN [HumanResources].[EmployeeDepartmentHistory] edh
ON [de].[DepartmentID] = [edh].[DepartmentID]
JOIN [HumanResources].[Employee] e
ON [edh].[EmployeeID] = [e].[EmployeeID]
JOIN [Person].[Contact] c
ON [e].[ContactID] = [c].[ContactID]
[de].[Name] LIKE 'P%'
FROM
WHERE
"
"
)
0
7+ @7<
) *5
&#
7
. $(#( #. 8
9 *
2 %4
3 + *
7
7
3
)
)
)*
L
*
%4
+
*
)
.
. $(#&'(
))
+
)
)
.
3
))
,(
E
($*
-
3
*
+
)
46 2 46
)
/)
)
=
3
% &
+
?
46 2 46
.
46 2 46
) :A
."
+*L
)
3
)
5
SELECT
[pm].[Name] AS ProductModelName,
[p].[Name] AS ProductName,
SUM([pin].[Quantity])
FROM
[Production].[ProductModel] pm
JOIN [Production].[Product] p
ON [pm].[ProductModelID] = [p].[ProductModelID]
JOIN [Production].[ProductInventory] pin
ON [p].[ProductID] = [pin].[ProductID]
GROUP BY [pm].[Name],
[p].[Name] ;
"
$#
+
)
+
2
.
5
.
!! !
)*
))
%4
#
1
0
&#
.
&#
.
2
2
)
%4
%4
1
)
4
)
SELECT
3
+
[pm].[Name] AS ProductModelName,
[p].[Name] AS ProductName,
SUM([pin].[Quantity])
FROM
[Production].[ProductModel] pm
JOIN [Production].[Product] p WITH ( FASTFIRSTROW )
ON [pm].[ProductModelID] = [p].[ProductModelID]
JOIN [Production].[ProductInventory] pin
ON [p].[ProductID] = [pin].[ProductID]
GROUP BY [pm].[Name],
[p].[Name]
)
2'
45
"
67
% $
=
) + L
5
#
3
))
)
) .
) * )
#
.
)
*
)
1 +
+ *
.% %& $
)
<
3 +
)
3
+
7
. %%# #
)
4 '
3
+*
)
1
.
)
+
*
.
*
1
*
#
%
*
. L
.
)
W%(
)
+
.W
Q<
*
!
8
<
)
.
)
.>
. -
<
1
)
3
)
*. - ?
.!
.
*
*
)
)
*
)
+
+
+E
)
3
+
(A
. '( $( $
*
+
*
+
,$%
:A
. 9 * +
7
*
+
.9 * +
.
+*
/
)
)
0.
))
)
+
)
+
3
))
.
+
)
+)
)
- *
+
7
7
.
.
+
)
)
@?A
7
7+
)
*
)
"
7
+
-
*
+
$6&0 3$-6
8
. L
)
*
3
*
)
*
))
.
DECLARE CurrencyList CURSOR FOR
SELECT CurrencyCode FROM [Sales].[Currency]
WHERE Name LIKE '%Dollar%'
OPEN CurrencyList
FETCH NEXT FROM CurrencyList
WHILE @@FETCH_STATUS = 0
BEGIN
-- Normally there would be operations here using data from cursor
FETCH NEXT FROM CurrencyList
END
CLOSE CurrencyList
DEALLOCATE CurrencyList
GO
%5
&5
"
<
% #
$"
C
7
7
K,
6
)
+
67
.
*
K
3
) 7
"
8 L
.
5
%(
"
*
.
7
4 # 8&
"
*
.
+*
+*L
7
7
4+
+*
)
*0.
%'
3
3
*.
)
)
3
*
+
/
&5
"
<
%(%
&
*
.
"
*
7
4+
7+
*
*0. L
*
)
K*
K.
-)
+*
:
)
7
+)
+*
)
6
/*
9
L
* )
.
L
+
) 05
%(
"
<
+* )
<
+*
+
+
) )
) )
)R
.
.
*
+
))
"
,?A 3
:A
&
&
&
)
:
$6&0 &
* )
:A
=
+
.
##
7)
*
) +*
)
)
&
7
##.
L
:
4
+)
(*
OPEN CurrencyList
FETCH NEXT FROM CurrencyList
)
)
.
)
+
$3 &
&5
"
<
%((
'
:A
$6&0 & 4
+)
/025$
+
& 3<
.
WHILE @@FETCH_STATUS = 0
BEGIN
--Normally there would be operations here using data from cursor
FETCH NEXT FROM CurrencyList
END
"
+:
.
CLOSE CurrencyList
DEALLOCATE CurrencyList
"
##
&
%('
$"
8
* 7
7
"
K,
67
*
K
* 5
))
*
/
)
* )
) * + ))
0.
<
.
+ $6&0 &
:A
4$5$&6
) +
. L
+
"
#$
$6&0
.
7
*
+
7
+
.
)
*
$6&0
))
+*
$"
)
))
.8 L
.
7*L
,
C
.
) )
*5
5 !
" *
*
3
"
#%
7
3
.F
+ *
1
.
)
.
.
%'
&5
<
%(4
+
4 # 8&
+ *
. ,
%4
4 !
)
.
+
+
+ L
4 !
+*
7
3
"
#&
*
7*
)
))
3
.
K%K )
+ 4
+ :A
+
)
+*
> .
.
)
)
"
.
A**J.
*
.
.
K7 :7
+ L
*
7.
#)
) +
:
7
.
*
*
%(&
#
:
K
K
*
+)
)
*
/
+
*
:
7. "
3
*
70.
* )
+
7
:
.
)
+
+
L
4
+*
+
.
+*
+
) .
.
*
7
)
*
7
* *
*
#
)*
)
3
3
67
7.
* ) :
/025$
"
+*
*
*
*+ *
+
)
##
7
*
*
7
)
$3 &
*
4
. "
*
*
)
.8
&5
"
<
%($
):
$6&0
+
K
+
*
.
D
* )
)
)
7
A L
+ ))
)
)
) )
* 7
)
5
5 !
#
7
"
#$
%#5
+
.
%(
" *
*L
*
R
)
)
*.
)
+
+ L
) )
+
.
*
))
)
*
)
:
.
"
)
)
7
"
:
:
4 # 8&
+* )
)
+
*
.
+
.
*
&
4
)
+ )
)
)
&#
2 %
1
.
+
)
*
1
D
)
"
#
8
"
+*
$3 &
%5
.
&
:
4
+
)
$6&0 3$-6
))
+ L
)
3
*
.,
$6&0
*
.8
.
* +
) *
&5
<
%(#
B$% :
6
)
. )*
+ 7
)
+
$ <7 35
*
K,
67
K5
DECLARE CurrencyList CURSOR READ_ONLY FOR
"
)
)
&
*
7
*
+
.
.C
.
) Q<+
+ 7
*
)3
) )
)
)
)
*
)
*
)
)3
)
)
.
)
+*
+
*
)
L
+*
)
+
.
+
INTO @WorkTable
(
[Name]
,[OrderDate]
,[TotalDue]
)
3
7
.
*L
)
.
%'
SELECT
s.[Name]
,soh.[OrderDate]
,soh.[TotalDue]
FROM
[Sales].[SalesOrderHeader] AS soh
JOIN [Sales].[Store] AS s
ON soh.[CustomerID] = s.[CustomerID]
WHERE
soh.[CustomerID] = 17
ORDER BY soh.[OrderDate]
DECLARE ChangeData CURSOR
FOR SELECT [DateOrderNumber]
,[TotalDue]
FROM
@WorkTable
OPEN ChangeData
FETCH NEXT FROM ChangeData INTO @DateOrderNumber, @TotalDue
WHILE @@FETCH_STATUS = 0
BEGIN
-- Normally there would be operations here using data from cursor
IF @TotalDue < 1000
UPDATE @WorkTable
SET
SaleType = 'Poor'
WHERE
[DateOrderNumber] = @DateOrderNumber
ELSE
IF @TotalDue > 1000
AND @TotalDue < 10000
UPDATE @WorkTable
SET
SaleType = 'OK'
WHERE
[DateOrderNumber] = @DateOrderNumber
ELSE
IF @TotalDue > 10000
AND @TotalDue < 30000
UPDATE @WorkTable
SET
SaleType = 'Good'
WHERE
[DateOrderNumber] = @DateOrderNumber
ELSE
UPDATE @WorkTable
SET
SaleType = 'Great'
WHERE
[DateOrderNumber] = @DateOrderNumber
FETCH NEXT FROM ChangeData INTO @DateOrderNumber, @TotalDue
END
CLOSE ChangeData
DEALLOCATE ChangeData
SELECT
FROM
8
)
*
@WorkTable
3
Number
1
2
3
4
5
6
7
8
9
10
11
12
Name
Trusted
Trusted
Trusted
Trusted
Trusted
Trusted
Trusted
Trusted
Trusted
Trusted
Trusted
Trusted
Catalog
Catalog
Catalog
Catalog
Catalog
Catalog
Catalog
Catalog
Catalog
Catalog
Catalog
Catalog
67
OrderDate
2001-07-01
2001-10-01
2002-01-01
2002-04-01
2002-07-01
2002-10-01
2003-01-01
2003-04-01
2003-07-01
2003-10-01
2004-01-01
2004-04-01
Store
Store
Store
Store
Store
Store
Store
Store
Store
Store
Store
Store
+
.
0
+
7
+ 4 #8
+
0
TotalDue
18830.1112
13559.0006
51251.2959
78356.9835
9712.8886
2184.4578
1684.8351
1973.4799
8897.326
10745.818
2026.9753
702.9363
)
)
*
+
4 # 84
SaleType
Good
Good
Great
Great
OK
OK
OK
OK
OK
Good
OK
Poor
)
3
&5
<
%'%
)
$ ))
.
A L
)
)
"
)
%%(
67
)
.
+*
8
)
)
)
+*
*.
)
)
)
+*
)
+*
*
)
*
.
$6&0 &
)
)
&S )
+
+*
4S )
)
.
+*L
" *+ *
67
"
"
)
*
.9 *
) %S
* L
.
)
+
*
3
+
7
%'
'&
*3
$4
.
A L
) .
"
&
+
+
67
%S+
)
*
/(
)
A L
" *+
"
&5
$6&0 )
) %S )
)
)
)*
+
+
L
+
'
.
.A L
5
&5
<
%'(
/ <7 35
$ <7 35
.
+
/
467
L
) *
*
/
<
+*
.A L
<7 35
)
)
)*
&
$ <7 35 +
.9 * +
<7 35 5
)
D6F 6
.
3
+
*
.
9 *
+*
)*
;8
5
SELECT ROW_NUMBER() OVER(ORDER BY soh.[OrderDate])
,s.[Name]
,soh.[OrderDate]
,soh.[TotalDue]
,CASE
WHEN soh.[TotalDue] < 1000
THEN 'Poor'
HEN soh.[TotalDue] BETWEEN 1000 AND 10000
THEN 'OK'
WHEN soh.[TotalDue] BETWEEN 10000 AND 30000
THEN 'Good'
ELSE 'Great'
END AS [SaleType]
FROM
[Sales].[SalesOrderHeader] AS soh
JOIN [Sales].[Store] AS s
ON soh.[CustomerID] = s.[CustomerID]
WHERE
soh.[CustomerID] = 17
ORDER BY soh.[OrderDate]
. !
4 #
.
7
)
7
"
))
'
+*
)
+
)
.
*
)
+*
*
)
4'S
3
)
*
.
*
7
.9 *
L
)
*
+
=
))
.
*
1
)
*
+ *
)
*+ *
)
*
)
))
*
*
* % +
)
.
)% +
%''
*
*
!
?
)
)
)
7
,
+
:A
:A
.
)
+
L )
)
.
)
.9 * +*
1 *
*
+*
.
*
))
)
. <
7
))
)
)
+
*
) *
*
.
)..
+
5
&5
<
%'4
%'&
(C
. /+ ,% / ' ,$%
8
)
) :A
+
4+ @?A
)@?A+ *
.
F
* @?A
%.
:A
@?A
@?A
@?A+
) @:
3
@?A
7 .
@?A
@:
@?A
< 6"@?A
@?A
3
)
+
+
@?A
<> @?A
3
. :
(.
*
'.
)
8 *
)
+
)@?A
3
))
)
.
<> @?A
*
))
@?A *
:A
*
* ) @?A
< 6"@?A 3
5
*
@?A
<> @?A
*
:A
< 6"@?A
.8 * 7
*
.6
))
@:
7
. < 6"@?A
7
)
.
@:
)*
7
)
* *
7
7
3
* .
@?A
3
)* *
C
@?A+
:A.
)
))
+*
.
.
@?A
*
+*
@?A+
:A
.
+
@?A 3
@?A
)
)
:A
3
+
+
$( /+
)
*
.F
6
)
6 P
@?A
0
/P
)
L : MN
)
$- 52&26 P
*
3
)
60 P )
)
*
.
3
7
@?A)
+
) ) *
- 5
)
@?A
@?A
+*
.
7
@?A
3
.
. 8
*
) 3
<> @?A
)
$- 52&26 )
.
))
))
@?A
:A
*
*
$5 @?A
)
.
67
%'$
3
3
)
)
3
3
) *
)
- 5
@?A
.9 L
SELECT
c.[FirstName],
c.[LastName],
c.[EmailAddress],
c.[Phone],
e.[EmployeeID],
e.[Gender],
a.[AddressLine1],
a.[AddressLine2],
a.[City],
a.[StateProvinceID],
a.[PostalCode]
[Person].[Contact] c
INNER JOIN [HumanResources].[Employee] e
ON c.[ContactID] = e.[ContactID]
INNER JOIN [HumanResources].[EmployeeAddress] ea
ON e.[EmployeeID] = ea.[EmployeeID]
INNER JOIN [Person].[Address] a
ON ea.[AddressID] = a.[AddressID]
XML AUTO
FROM
FOR
"
)
*L
%5
))
. L
7
.
SELECT
)
.<
A L
.
+
*
-C <
:A 6A6
*
L
K
3
K3
+*
.
- 5 4$5$&6
+3
5
s.Name AS StoreName,
c.ContactID,
c.ContactTypeID
FROM
Sales.Store s
JOIN [Sales].[StoreContact] c ON s.[CustomerID] = c.[CustomerID]
ORDER BY s.[Name]
FOR
XML AUTO
%'
"
.% .
@?A
*5
+ )*
- 5 $- 52&26
*
3
P) 7
) @?A )
+
)
3
- 5
+ )
8
)
- 5
@?A
- 5 $- 52&26+
+
@?A
6 .
*
3
) 32 3
*
.9
SELECT
1 AS Tag,
NULL AS Parent,
s.Name AS [Store!1!StoreName],
NULL AS [Contact!2!ContactID],
NULL AS [Contact!2!ContactTypeID]
FROM
Sales.Store s
JOIN [Sales].[StoreContact] c ON s.[CustomerID] =
c.[CustomerID]
UNION ALL
SELECT 2 AS Tag,
1 AS Parent,
s.Name AS StoreName,
c.ContactID,
c.ContactTypeID
FROM
Sales.Store s
JOIN [Sales].[StoreContact] c ON s.[CustomerID] = c.[CustomerID]
ORDER BY [Store!1!StoreName],
[Contact!2!ContactID]
FOR
XML EXPLICIT
(5
$5 @?A
"
*5
67
%'#
. #.
@?A
- 5 $- 52&26
)@?A
+
)
)
.
.8
<> @?A 6@ A
.
)
* +
7
+
6
+
)
*
*+
@?A
+*
+
C" <"
L
))
L
@?A+ *
+
7
)3
)
+
3
.
-
- 5
*
)
3
*
:A
)
6
@?A
3
+
$
.
s.[Name] AS StoreName,
( SELECT
c.ContactID,
c.ContactTypeID
FROM
[Sales].[StoreContact] c
WHERE
c.[CustomerID] = s.[CustomerID]
FOR
XML AUTO,
TYPE,
ELEMENTS
)
FROM
[Sales].[Store] s
ORDER BY s.[Name]
FOR
XML AUTO,
TYPE
*
+
*
7
45
SELECT
$5$ $364
*
@?A5
%4
<s StoreName="A Bicycle Association">
<c>
<ContactID>956</ContactID>
<ContactTypeID>11</ContactTypeID>
</c>
</s>
"
))
'5
)
7
@:C6>F
*
*
@?A
"
))
*+ *
5
. (. *
*
<@ - 9
@?A
C,@
.
C,@
.@ - 9
+
7
)
@:C6>F
.
*
&
&
2<
7
$% A**K+ *
&
6 2<.
4
.
)
1
7 C,@
&
)
*
$5 @?A
%4%
*
@?A )
)
@?A.
) )
+
67
- 5 60
7
*
*
+
/
0+ )
@?A
.C
*L
SELECT
s.[Name] AS "@StoreName",
c.[ContactID] AS "StoreContact/@ContactId",
c.[ContactTypeID] AS "StoreContact/@ContactTypeID"
FROM
[Sales].[Store] s
JOIN [Sales].[StoreContact] c ON s.[CustomerID] =
c.[CustomerID]
ORDER BY s.[Name]
FOR
XML PATH
7
/.% 0.
@?A
*5
<)
)
*
*
7
@?A
)
.
)
)* @:
>
@?A
+
) *
:A.
)
)
+
7
@?A
+
@?A
) 3
.8
) @?A - 9
@
+
@?A
)
*
.
:A
+
+
@?A -C <
5
Table 'StoreContact'. Scan count 1, logical reads 7,
Table 'Store'. Scan count 1, logical reads 103,
9 *
)
+
@?A 6@ A
5
@?A
@?A - 9
-C <
) .
@?A -C < *
F 6*
)
C,@
%/+
@?A*
@?A
) *
:A
+
)
< 6"@?A @:
. < 6"@?A
+)
*
+
*
:A
. L
%4
)
@?A )
+*
@?A
<ROOT>
<Currency CurrencyCode="UTE" CurrencyName="Universal Transactional Exchange">
<CurrencyRate FromCurrencyCode="USD" ToCurrencyCode="UTE"
CurrencyRateDate="1/1/2007" AverageRate=".553" EndOfDateRate= ".558" />
<CurrencyRate FromCurrencyCode="USD" ToCurrencyCode="UTE"
CurrencyRateDate="6/1/2007" AverageRate=".928" EndOfDateRate= "1.057" />
</Currency>
</ROOT>
+*L
C 6. 8
+
*
7
C
)
+
67
C 6
)
C ,. 8 L
@?A. 9 L
*
5
BEGIN TRAN
DECLARE @iDoc AS INTEGER
DECLARE @Xml AS NVARCHAR(MAX)
SET @Xml = '<ROOT>
<Currency CurrencyCode="UTE" CurrencyName="Universal Transactional Exchange">
<CurrencyRate FromCurrencyCode="USD" ToCurrencyCode="UTE"
CurrencyRateDate="1/1/2007" AverageRate=".553" EndOfDayRate= ".558" />
<CurrencyRate FromCurrencyCode="USD" ToCurrencyCode="UTE"
CurrencyRateDate="6/1/2007" AverageRate=".928" EndOfDayRate= "1.057" />
</Currency>
</ROOT>'
EXEC sp_xml_preparedocument @iDoc OUTPUT, @Xml
INSERT
INTO [Sales].[Currency]
(
[CurrencyCode],
[Name],
[ModifiedDate]
)
SELECT CurrencyCode,
CurrencyName,
GETDATE()
FROM
OPENXML (@iDoc, 'ROOT/Currency',1) WITH ( CurrencyCode NCHAR(3),
CurrencyName NVARCHAR(50) )
INSERT
INTO [Sales].[CurrencyRate]
(
[CurrencyRateDate],
[FromCurrencyCode],
[ToCurrencyCode],
[AverageRate],
[EndOfDayRate],
[ModifiedDate]
)
SELECT CurrencyRateDate,
FromCurrencyCode,
ToCurrencyCode,
AverageRate,
EndOfDayRate,
GETDATE()
FROM
OPENXML(@iDoc , 'ROOT/Currency/CurrencyRate',2) WITH (
CurrencyRateDate DATETIME '@CurrencyRateDate', FromCurrencyCode NCHAR(3)
'@FromCurrencyCode', ToCurrencyCode NCHAR(3) '@ToCurrencyCode', AverageRate MONEY
'@AverageRate', EndOfDayRate MONEY '@EndOfDayRate' )
EXEC sp_xml_removedocument @iDoc
ROLLBACK TRAN
3
234$ 6
+ *
*
&
7
+
+
*
)
&5
234$ 6.
$5 @?A
"
67
%4(
- 3
)
*
,AA *
:A
+ *
*
)
* @?A
.
@?A
3
)+
. -
< 6"@?A
)
)
>
.
67
)
3
'
"
7
@?A
7% #7
:A
+
@?A
)
7% #7.
$.
*
.9
*
+
) @?A
< 6"@?A
.
+*
)
@?A
<
)
A )
+
"
+ L
) *
*
)
7
7
"
) )
7
234$ 6
&
.
5
3
+ *
)
) )
@?A
* * )
+
*
)
&
7
&
)
. F
>
.
?
)
+ *
+ )
%4'
&
E +
&
6 &
<
&
=
)
.
@?A
. -
)
*
+ < 6"@?A
*
<
*
@?A+
.
)
4$5$&6
)
+
1
< 6"@?A
3
..
*
5
)
)
+
)
@?A
.
*
@?A
+
+
7
.
)
. F
@?A
!
-
)
) @:
*
@:
.8
)*
8
8' #
8
8 %
(+5
(+5
(+5
(+5 3
3
3
4+
+
:A.
)
@?A
:A
+
7
7
7
7
7
*
!
$-2464
+
:A
@?A
.
3
0
1
:A
. 6))
@:
)
@?A
+
))
* 5
)
7
+1
)
)
@?A
*3
8
(+5
@?A
@?A
) 3
)7
7
3
@?A+
3
*
*
3
) A8 <> /) + +
7
. L
))
. L
)
*
'
8 %
.
*
3
)
)
SELECT
+*L
*
)3
*
)
@?A
)
c.[LastName],
c.[FirstName],
e.[HireDate],
e.[Title]
FROM
[Person].[Contact] c
INNER JOIN [HumanResources].[Employee] e ON c.[ContactID] = e.[ContactID]
INNER JOIN [HumanResources].[JobCandidate] jc ON e.[EmployeeID] =
jc.[EmployeeID]
AND jc.[Resume].exist('
declare namespace res="http://schemas.microsoft.com/sqlserver/2004/07/adventureworks/Resume";
/res:Resume/res:Employment/res:Emp.JobTitle[contains(.,"Sales Manager")]') = 1
$5 @?A
3
67
%44
+)
"
%4
% 5
+
)
* )
+*
1 &
)
>
)
1 &
* *.
=#
.-3
5
.
)
>
>
. - &#
#
$
+)
)
*
+ 6 #
K@?A >
* @
) K.
)
@:
.
)
< 6"@?A 3 . 9 * +
+
) 3
B+
) *
1
)
7
.
"
* *
)
3
@
5
#%#
*
3
#
.
L
*)
7
)
.
&
*
.
%4&
'
@?A.
7
=.
)
@?A
8
+<
>
@?A
+
+
+
Q6
/
P
/0$ $
P
P
:A 7
@:
7
+
94
4 ' .
:A
+1
)
)
)
3
@?A
*
.A L
0
4$5$&6
.
:A
* *
/ + A +
)@:
+
:A/
)
) )
+*
)
)
<$
+*
L
7
)@?A
# 7
,
3 +*
A8 <> 7
0.
:A5
+*L 3
4.
)
) .
.
7
)
@?A
5
)
7
+*L
SELECT s.Demographics.query('
declare namespace
ss="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/StoreSurvey";
for $s in /ss:StoreSurvey
where ss:StoreSurvey/ss:SquareFeet > 20000
return $s
') AS Demographics
FROM
[Sales].[Store] s
WHERE
s.[SalesPersonID] = 279
"
)*
4 #
-3
*
:A3
2 E ,OP+
.3
* +
* *
*
L 3
)
* 3
..
4
)
L
)
4 #
+)
) ) 3
5
+ )
)
1 +* )
)
@?A
% .
4 #
)
2.
&#
1 .
)
5 &#
7.
2
)
%4
$5 @?A
"
67
#$
F
!
%4$
*
4
%(
* )
&#
7
7
%4
.
2
)
&
- 574
7<
!
2 ) )
&
2+
+
.
A )E .
+
<-
)
*
7*
)
4
) *
*
) @?A
@?A
.
. <)
)
:A.
* )
+
)
*
)
@:
)
@?A
)
!
7
L
@?A
)
.
Q
)
*
Q ('4% .
)*
.F
*
)*
))
70.
.
7
)
*
)
)) .
?
@:
:A
.
@:
L
+
) / 5QQ
) <> @?A+
).
%4
F
@:
* L
*
)
*
* )
) < 6"@?A.
< 6"@?A.
@?A
+
)
*
.
*
*
@:
:A *
:A
.L
$5 @?A
67
%4#
%&
(D
.
3%
+ *
7
)
.
:A
* 7
+* *
*
*
=
P
)
7 =
)
+
7
P*
73
+
*+
7 +
*
*
+
*
)7
1 +
+*
7
)
*
$ ,
7
*
R
C
.C
+ :A.
1
3
P
)
.
)
=.
(
*
)
.
7+
=
+*
9 * +
+ L
+
*
+*
)
)
.
*
*
0.
.
*
.
L
+
))
))
+ ))
L
)
7
)
*
7+
= +* +
A L
L
)
)1 +
*
3
.
.
+
+ )
))
5-
%&%
WHERE
BEGIN
SELECT
FROM
WHERE
ON soh.[SalesOrderID] = sod.[SalesOrderID]
INNER JOIN [Sales].[SpecialOffer] spo
ON sod.[SpecialOfferID] = spo.[SpecialOfferID]
i.[ContactID] = @ContactId
AND spo.[SpecialOfferID] = @SpecialOfferId )
END
-- use different query to return other data set
ELSE
BEGIN
SELECT c.[LastName] + ', ' + c.[FirstName]
,c.[EmailAddress]
,i.[Demographics]
,soh.SalesOrderNumber
,sod.[LineTotal]
,p.[Name]
,p.[ListPrice]
,sod.[UnitPrice]
,st.[Name] AS StoreName
,ec.[LastName] + ', ' + ec.[FirstName] AS SalesPersonName
FROM
[Person].[Contact] c
INNER JOIN [Sales].[Individual] i
ON c.[ContactID] = i.[ContactID]
INNER JOIN [Sales].[SalesOrderHeader] soh
ON i.[CustomerID] = soh.[CustomerID]
INNER JOIN [Sales].[SalesOrderDetail] sod
ON soh.[SalesOrderID] = sod.[SalesOrderID]
INNER JOIN [Production].[Product] p
ON sod.[ProductID] = p.[ProductID]
LEFT JOIN [Sales].[SalesPerson] sp
ON soh.SalesPersonID = sp.SalesPersonID
LEFT JOIN [Sales].[Store] st
ON sp.SalesPersonID = st.SalesPersonID
LEFT JOIN [HumanResources].[Employee] e
ON sp.SalesPersonID = e.[EmployeeID]
LEFT JOIN Person.[Contacct] ec
ON e.[ContactID] = ec.[ContactID]
WHERE
i.[ContactID] = @ContactId;
END
--second result SET
IF @SpecialOfferId = 16
BEGIN
SELECT p.[Name]
,p.[ProductLine]
FROM
[Sales].[SpecialOfferProduct] sop
INNER JOIN [Production].[Product] p
ON sop.[ProductID] = p.[ProductID]
WHERE
sop.[SpecialOfferID] = 16;
END
%&
END TRY
BEGIN CATCH
SELECT ERROR_NUMBER() AS ErrorNumber
,ERROR_MESSAGE() AS ErrorMessage ;
RETURN ERROR_NUMBER() ;
END CATCH
RETURN 0 ;
;
)
!
))
3
)
3
C )
8 L 7
.
.
+
+
)
.
,!-
.
*
EXEC [Sales].[uspGetDiscountRates]
@ContactId = 12298, -- int
@SpecialOfferId = 16 -- int
"
#&
)
*
3
*
+
+
)
5
)
))
5-
%&(
"
<
*+
)
)
3
7
*
)
%&.
+*
* . 9 * +
)
)) .
)) .
7
. L 1
*
3
)
) *
2< V
) .
.
*
*
*
*+ *
(5
.
L
*
7
F L
)
+
+
*
"
+
4
*
L
)
)
.D
K
*+
*
+
K
)
*
+
*.
'5
%&'
"
+
.
)*
L
* +
7 )
L
)+
/& S0+
'
#
*
+
7
*
)
."
*
*
+
@?A
7
@?A *
+
.
7
)
7
1
)
+ )
+
*
:A
.!
. )
* )
))
)
*
.,
.E
L
.
2<
&
.-
%4
= )
) 3
))
*
+
@?A
+
+
L 1
@?A+
*
1
&#
)
8
*
)
3
4 # 82
+
7
)+
5
K
%< !
*
K& 6
#
*
:A
)
*
### K+ *
7
3
.
### K+ *
)
.!
:A
K K+ *
.
3
K4K.
+
:A
/
)
*
)
0. ! ) +
7
3
*
.
)K%K. )
5-
%&4
)
+
&'.%(
!<A /
5QQ
7
.
!
).
Q % % $.
+ ) *5
70+
*
*
)
)
7
. )
)
+*
K
.
<
'
'
# #
*5
:A
.
' # #Q
+
)
<
.
)
+
Q:
*
1
. L
:
))
Q
+*
) *
Q,
=
)
*
8
+ )
+
3
+
*
%
) )
.
8
)
+
L
7
+
)
*
+
?-@,< 3
.8
3
*
)
%(
' 5
))
+
)
4.
+
+
%&&
&
0
.
*
+
F L
)
)
<A
*
)
+
3
-<
7
. )
(+
* *
. )
))
)
:A
:A
?
..F
) )
*
-<
+
+
. :
%
*
7
.9 *
+ L
)
L
+
)
*
.D
,
= +2
< RP)KPO /
?
+
K K+ *
.
7
)+
)3
)+
* *
.
.
.
) +
.
+ *
7
)
+*
1
)
* .-3
+ *
*
* L
)
0.
:A
)
7
.
)
'
.
8 L
3
9
. )
*
) )
SELECT
[so].[ProductID]
,COUNT(*) AS Order_Count
FROM
[Sales].[SalesOrderDetail] so
WHERE
[so].[ModifiedDate] >= '2003/02/01'
AND [so].[ModifiedDate] < DATEADD(mm, 3, '2003/02/01')
GROUP BY [so].[ProductID]
ORDER BY [so].[ProductID]
)*
*
"
+*L
) *
45
&
*
) *
=
*
+
) +
)
*L
*
)
.
%)
5-
%&$
* /4
) 0.
+*
5
sp_configure 'cost threshold for parallelism', 1 ;
GO
RECONFIGURE WITH OVERRIDE ;
GO
SET STATISTICS XML ON;
GO
SELECT [so].[ProductID]
,COUNT(*) AS Order_Count
FROM
[Sales].[SalesOrderDetail] so
WHERE
[so].[ModifiedDate] >= '2003/02/01'
AND [so].[ModifiedDate] < DATEADD(mm, 3, '2003/02/01')
GROUP BY [so].[ProductID]
ORDER BY [so].[ProductID]
GO
SET STATISTICS XML OFF;
GO
"
67
@?A
&5
+
*
+
*
.
. )*
*
*
*+ *
*
@?A
+*
5
<QueryPlan DegreeOfParallelism="2" MemoryGrant="162" CachedPlanSize="22"
CompileTime="5" CompileCPU="5" CompileMemory="320">
) +
*
7
+*L )
)
2
< !
*
+ *L
3
%4
)
###
*
7
. A
. - *
* )
@?A 7
)
&#
.
*
&#
%4
"
###
%+
0. 8
/
+
%&
)
&
.
*
7
###
)
)
0
) +
2<
+*L
.
4 # <
<
)
.
+
+ *
)
###
5
<RelOp NodeId="0" PhysicalOp="Parallelism" LogicalOp="Gather Streams"
EstimateRows="261.129" EstimateIO="0" EstimateCPU="0.0301494" AvgRowSize="15"
EstimatedTotalSubtreeCost="1.1394" Parallel="1" EstimateRebinds="0"
EstimateRewinds="0">
<RunTimeInformation>
<RunTimeCountersPerThread Thread="0" ActualRows="99" ActualEndOfScans="1"
ActualExecutions="1" />
</RunTimeInformation>
)
)
4
4
))
+
)
+*
<
)
.
-
6
)
+ )
+*L
5<
%&#
L
*
+
)
40.
1
=
*
)
V 4 K+
)*
K7
. .
3
7
. 8
)
=
*
*
.
<$5$6$
&#
%< #
4 +
"
))
)
)
=
L 1
3
+
%$
=
)
+
3
*
7. -
@:
7
= .
=
+
+*
+)
.
+ :A
7
)
5
4$5$&6
*
C, + *
7
*
=
+
)
)
:A
)
* .
<
.6
+
7
.
+
3
7
+
=
*
=
-
))
*
=
3
+ )
.- *
+
. F
3
&$<+
.
+*
+*
)
*
FROM
WHERE
>
.
)
)
$6$ 2G 62 3
7
+*
L5
42 AS TheAnswer
,c.[EmailAddress]
,e.[BirthDate]
,a.[City]
[Person].[Contact] c
JOIN [HumanResources].[Employee] e
ON c.[ContactID] = e.[ContactID]
JOIN [HumanResources].[EmployeeAddress] ea
ON e.[EmployeeID] = ea.[EmployeeID]
JOIN [Person].[Address] a
ON ea.[AddressID] = a.[AddressID]
JOIN [Person].[StateProvince] sp
ON a.[StateProvinceID] = sp.[StateProvinceID]
c.[EmailAddress] LIKE 'david%'
AND sp.[StateProvinceCode] = 'WA' ;
3
SELECT
+L
=
+
=
)
SELECT
)
:A
)
)
)
.
)
*
"
) +
.
;-
9 *
+
)
)
)
.
.
)
[cp].[refcounts]
,[cp].[usecounts]
,[cp].[objtype]
,[st].[dbid]
%)
05
5-
%$%
,[st].[objectid]
,[st].[text]
,[qp].[query_plan]
sys.dm_exec_cached_plans cp
CROSS APPLY sys.dm_exec_sql_text(cp.plan_handle) st
CROSS APPLY sys.dm_exec_query_plan(cp.plan_handle) qp ;
FROM
*
.
* *
*
5
"
A L
*
* 7
))
*L
3
. 9 *
)
/)
+
+
3
05
(@0 varchar(8000))
select 42 as TheAnswer
,c.[EmailAddress]
,e.[BirthDate]
,a.[City]
from
[Person].[Contact] c
join [HumanResources].[Employee] e
on c.[ContactID] = e.[ContactID]
join [HumanResources].[EmployeeAddress] ea
on e.[EmployeeID] = ea.[EmployeeID]
join [Person].[Address] a
on ea.[AddressID] = a.[AddressID]
join [Person].[StateProvince] sp
on a.[StateProvinceID] = sp.[StateProvinceID]
where
c.[EmailAddress] like 'david%'
and sp.[StateProvinceCode] = @0
+
+
)
)
*
4
+
& 46
+ F *'
3
*
'
+
)
&
) .
B-> 9->/
(B***+.
)
+
))
*
9->/(0.
%$
9 *
*
+ )
+
!)
3
.
))
'
+
)
3
*L
:A
*
)
) + )* *
)
7+
+
*
#
3
*
:A
+ *
+ *
*
7
.
*
*
* .
:A
1 +
)
)
:A
5 7
*
)
7
)
>
4?5
6
7 # 7!
5
P
+)
P
7 )
P
* .
1 .
)
+
,?A
:A
1
)
+*
' 3
$#E
A L
)
8
*L
! $
#
+
)
+
$&
25$
)
7
L
*
A L
8
.
+
.9 *
*
.
L
5-
%$(
ON e.[ContactID] = c.[ContactID]
)
-- Join back to Employee to return the manager name
SELECT [EMP_cte].[RecursionLevel], [EMP_cte].[ManagerID], c.[FirstName] AS
''ManagerFirstName'', c.[LastName] AS ''ManagerLastName'',
[EMP_cte].[EmployeeID], [EMP_cte].[FirstName], [EMP_cte].[LastName] -Outer select from the CTE
FROM [EMP_cte]
INNER JOIN [HumanResources].[Employee] e
ON [EMP_cte].[ManagerID] = e.[EmployeeID]
INNER JOIN [Person].[Contact] c
ON e.[ContactID] = c.[ContactID]
ORDER BY [RecursionLevel], [ManagerID], [EmployeeID]
OPTION (MAXRECURSION 25) ', @type = N'OBJECT',
@module_or_batch = N'dbo.uspGetManagerEmployees', @params = NULL,
@hints = N'OPTION(RECOMPILE,MAXRECURSION 25)'
+ *
F
."
+
7 )
.
F
.8
+
6. 8
+
3
L
.8
.
1 +
#7 7
1
F
*L
+
+*
.8
)
* .
)* L
)
+
3
F
7
) * +*
62 3
) *
+
+ *
7
A L
:A
)*
*L
*
*
62 3R
. 8
$&
42 3.
)+
+*
.
)
*
.
. )* *
)
7
1 + )* L
+ L
)
F
25$
$&
= )
.
F
*L
7
= *
.A L
.<
)
.
*L
+*L
62 2G$
)
+*L
.
+*
45
SELECT * FROM [Person].[Address]
WHERE [City] = 'LONDON'
4+ *
62 2G$
:A
5
*
(F &
E 3 :
)
++ 3
3
L
%$'
EXEC sp_create_plan_guide @name = N'MySecondPlanGuide',
@stmt = N'SELECT * FROM [Person].[Address] WHERE [City] = @0',
@type = N'SQL',
@module_or_batch = NULL,
@params = N'@0 VARCHAR(8000)',
@hints = N'OPTION(OPTIMIZE FOR (@0 = ''Newark''))'
)
+
)
3
= 3
*
L
*
3
*
7! 7
*
= *
7
# .
* *L
5
)
=
@0 varchar(8000)
" **
*
*
7
"
3
3
+*
* * +
.
)
#5
"
-
7
=
=
+
)*
)
*
+ *
# !
.
F
*
*
7! 7
= .
#
+
*5
5-
%$4
,e.[BirthDate]
,a.[City]
FROM
[Person].[Contact] c
JOIN [HumanResources].[Employee] e
ON c.[ContactID] = e.[ContactID]
JOIN [HumanResources].[EmployeeAddress] ea
ON e.[EmployeeID] = ea.[EmployeeID]
JOIN [Person].[Address] a
ON ea.[AddressID] = a.[AddressID]
JOIN [Person].[StateProvince] sp
ON a.[StateProvinceID] = sp.[StateProvinceID]
WHERE
c.[EmailAddress] LIKE ''david%''
AND sp.[StateProvinceCode] = ''WA''',
@type = N'TEMPLATE',
@module_or_batch = NULL,
@params = N'@0 VARCHAR(8000)',
@hints = N'OPTION(PARAMETERIZATION FORCED)'
)
8 # 7!
*+
)
7
+
#7 # 7!
+*
7 +
+
)
.
#7 # 7!
.
EXEC sp_control_plan_guide @operation = N'DROP'
,@name = N'MyFourthPlanGuide'
!
8
*L
)
.
. L
) *
.,
L )
*
1
'
4$ 5 3 3
+
3
@?A+
3
:A
7
K
4+
*
.
K+ ) 7
) * .
*
+
" 6> + C ,- 6
:
,
3
+1
,6A6 6 3
.
) I) *
73
3
)
4$ 5 3.
%$&
8
@?A
7
. )
+ @?A 7
3 +
.
3
*
7
+
+
4$ 5 3+ *
)
3
*
4 #
+
+
.
)
3
) F4 #
+
"
"
2< E ,OO+
##
)
)
7
)
. )
62 2G$
4$ 5 3
.8
+*L
+*
4$5$&6
* .
46 62462&4 - 5+ *
@?A
*
)
.
* * .8
)
+*L *
@?A5
5-
%$$
@?A
= )
3
+*L
@?A+ L
)
% $
))
@?A
+*
* L
.8
/
05
EXEC sp_create_plan_guide
@name = N'UsePlanPlanGuide',
@stmt = N'SELECT soh.[AccountNumber]
,soh.[CreditCardApprovalCode]
,soh.[CreditCardID]
,soh.[OnlineOrderFlag]
FROM
[Sales].[SalesOrderHeader] soh
WHERE
soh.[SalesPersonID] = @SalesPersonID --288 --277',
@type = N'OBJECT',
@module_or_batch = N'Sales.uspGetCreditInfo',
@params = NULL,
@hints = N'OPTION(USE PLAN N''<ShowPlanXML
" *+ *
"
* *
% 5
4$ 5 3+
*
*
.-
7
*
*.
!
8
+
=
)
*
3
3
)*
.
=
)
.
L
)
*
L
=
)
.E
4$ 5 3I
.!
* .
+
%$
,%
"
)> * + %%
8 96>6
+4
= + %$+ %
- -
@?A
- 6
-
+ %
@?A
+$
+ ( + %&
+ ( + &$
+ $
:A
) + %&+
( + ((+ %%%
!
+ ( + $#+ %%'
3
A
67
+ ( + $#
7
+ ($+ ( + (#+ 4&+ 4 + & + &%+ '+ 4+ #+ #'+
##+ % '+ % 4+ %% + %%(+ %%4+ %%$+ %%#+ % %+
% 4+ % &+ %( + %44+ %4&+ %&'+ %&$
67
67
+ %
6
>3
+ %
+#
>
+ %+ $+
+
+
+ %+ #+ ( + ( + $%+ $$+ $ + %+ % %
+ %(
9<8 I -
+ # + ##
+
+ $+ ( + $(
<)
+ %
+&
+ '+ $
+ #
@?A
AF+ $+ %$%
+ $%
+
@?A
+ %$
@?A
+ ( + &&+ %(
B *+
+ #%+ # + % 4+ % &
+ '
+%
%( + %'%
+ '+ ( + ($+ % %
67
<? C 6+ % (
, )
+ (
+ &&+ %(4
67
,!
+ (
+ %+
+ (%+ ( +
+ (+ % #+ %(#+
+ ((
+ &$+ %(
%'
+ ($+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