<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>BlogmyQuery - BMQ &#187; Hints for DML queries</title>
	<atom:link href="http://blogmyquery.com/index.php/tag/hints-for-dml-queries/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogmyquery.com</link>
	<description></description>
	<lastBuildDate>Tue, 07 Feb 2012 14:15:11 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Hints for DML queries</title>
		<link>http://blogmyquery.com/index.php/2006/07/hints-for-dml-queries/</link>
		<comments>http://blogmyquery.com/index.php/2006/07/hints-for-dml-queries/#comments</comments>
		<pubDate>Fri, 14 Jul 2006 23:30:00 +0000</pubDate>
		<dc:creator>QueryOptTeam</dc:creator>
				<category><![CDATA[Sqlserver]]></category>
		<category><![CDATA[Hints for DML queries]]></category>

		<guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:666196</guid>
		<description><![CDATA[<P class=MsoNormal style="MARGIN: 0in 0in 0pt">Not everyone knows that&#160;query level hints (like loop join) will impact the entirety of a DML query plan. This includes foreign key validation and indexed view maintenance.</P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p>&#160;</o:p></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt">Let us look at an example with two tables involved in a foreign key constraint.</P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><o:p>&#160;</o:p></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'">use tempdb<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'">go<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'"><o:p>&#160;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'">create table department(deptid int primary key clustered, deptname varchar(10))<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'">go<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'"><o:p>&#160;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'">create table employee(empid int primary key clustered, empname varchar(10), deptid int references department(deptid))<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'">go<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'"><o:p>&#160;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'">insert department values(1, 'Optimizer')<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'">go<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><o:p>&#160;</o:p></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt">At first glance, it might seem useless to provide a join hint for a scalar insert - like when inserting a row to the employee table – because the query contains no joins. However, this can make sense in presence of foreign key validations, because the Optimizer will automatically augment the query plan with a join for the purpose of validating the constraint. For example, this insert statement here</P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><o:p>&#160;</o:p></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'">insert employee select 1 empid, 'Stefano' empname, 1 deptid </SPAN><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-SIZE: 10pt; COLOR: red; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'">option (merge join)</SPAN></B><SPAN style="FONT-SIZE: 10pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><o:p>&#160;</o:p></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt">will produce a plan with a merge join between the employee and department tables. The join will enforce that the value of the deptid column actually exists in the primary table, department. The “Assert” operator will raise an error if a matching row is not found.</P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><o:p>&#160;</o:p></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'"><SPAN style="mso-spacerun: yes">&#160; </SPAN>&#124;--Assert<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'"><SPAN style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160; </SPAN>&#124;--</SPAN><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-SIZE: 10pt; COLOR: red; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'">Merge Join</SPAN></B><SPAN style="FONT-SIZE: 10pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'"><SPAN style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </SPAN>&#124;--Clustered Index Insert(employee)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'"><SPAN style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </SPAN>&#124;--Clustered Index Scan(department)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><o:p>&#160;</o:p></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt">Unfortunately, this technique is restricted to only query (vs. table) level hints, so&#160;it's not possible for example&#160;to force the indexes being used when accessing the other table involved in the constraint (department in the example). Also, TSQL syntax does not allow specifying query level hints for scalar inserts, like "insert table&#160;values...", but the easy workaround is to rewrite the statement&#160;as "insert select" like in the example. Update and delete statements do regularly accept query level hints.</P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><o:p>&#160;</o:p></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'">update employee set empname = 'Conor', deptid = 2 where empid = 1 </SPAN><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-SIZE: 10pt; COLOR: red; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'">option (loop join)</SPAN></B><SPAN style="FONT-SIZE: 10pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'"><o:p>&#160;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'"><SPAN style="mso-spacerun: yes">&#160; </SPAN>&#124;--Assert<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'"><SPAN style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160; </SPAN>&#124;--</SPAN><B><SPAN style="FONT-SIZE: 10pt; COLOR: red; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'">Nested Loops</SPAN></B><SPAN style="FONT-SIZE: 10pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'"><SPAN style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </SPAN>&#124;--Clustered Index Update(employee)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'"><SPAN style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </SPAN>&#124;--Clustered Index Seek(department)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><o:p>&#160;</o:p></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><BR style="mso-special-character: line-break"><BR style="mso-special-character: line-break"></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><o:p>&#160;</o:p></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt">Let us now look at slightly more complex example with an indexed view.<o:p></o:p></P>
<P class=NormalCourierNew style="MARGIN: 0in 0in 0pt"><BR><SPAN style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><FONT size=2><FONT color=#800000><FONT face="Courier New">use tempdb<o:p></o:p></FONT></FONT></FONT></SPAN></P>
<P class=NormalCourierNew style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><FONT size=2><FONT color=#800000><FONT face="Courier New">go<o:p></o:p></FONT></FONT></FONT></SPAN></P>
<P class=NormalCourierNew style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><o:p><FONT face="Courier New" color=#800000 size=2>&#160;</FONT></o:p></SPAN></P>
<P class=NormalCourierNew style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><FONT size=2><FONT color=#800000><FONT face="Courier New">SET ANSI_NULLS ON<o:p></o:p></FONT></FONT></FONT></SPAN></P>
<P class=NormalCourierNew style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><FONT size=2><FONT color=#800000><FONT face="Courier New">SET ANSI_PADDING ON<o:p></o:p></FONT></FONT></FONT></SPAN></P>
<P class=NormalCourierNew style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><FONT size=2><FONT color=#800000><FONT face="Courier New">SET ANSI_WARNINGS ON<o:p></o:p></FONT></FONT></FONT></SPAN></P>
<P class=NormalCourierNew style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><FONT size=2><FONT color=#800000><FONT face="Courier New">SET CONCAT_NULL_YIELDS_NULL ON<o:p></o:p></FONT></FONT></FONT></SPAN></P>
<P class=NormalCourierNew style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><FONT size=2><FONT color=#800000><FONT face="Courier New">SET NUMERIC_ROUNDABORT OFF<o:p></o:p></FONT></FONT></FONT></SPAN></P>
<P class=NormalCourierNew style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><FONT size=2><FONT color=#800000><FONT face="Courier New">SET QUOTED_IDENTIFIER ON<o:p></o:p></FONT></FONT></FONT></SPAN></P>
<P class=NormalCourierNew style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><FONT size=2><FONT color=#800000><FONT face="Courier New">go<o:p></o:p></FONT></FONT></FONT></SPAN></P>
<P class=NormalCourierNew style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><FONT size=2><FONT color=#800000><FONT face="Courier New"><SPAN style="mso-spacerun: yes">&#160;</SPAN><o:p></o:p></FONT></FONT></FONT></SPAN></P>
<P class=NormalCourierNew style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><FONT size=2><FONT color=#800000><FONT face="Courier New">create table t1(i int, j int)<o:p></o:p></FONT></FONT></FONT></SPAN></P>
<P class=NormalCourierNew style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><FONT size=2><FONT color=#800000><FONT face="Courier New">go<o:p></o:p></FONT></FONT></FONT></SPAN></P>
<P class=NormalCourierNew style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><o:p><FONT face="Courier New" color=#800000 size=2>&#160;</FONT></o:p></SPAN></P>
<P class=NormalCourierNew style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><FONT size=2><FONT color=#800000><FONT face="Courier New">create table t2(h int, k int)<o:p></o:p></FONT></FONT></FONT></SPAN></P>
<P class=NormalCourierNew style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><FONT size=2><FONT color=#800000><FONT face="Courier New">go<o:p></o:p></FONT></FONT></FONT></SPAN></P>
<P class=NormalCourierNew style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><o:p><FONT face="Courier New" color=#800000 size=2>&#160;</FONT></o:p></SPAN></P>
<P class=NormalCourierNew style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><FONT size=2><FONT color=#800000><FONT face="Courier New">create view v with schemabinding as<o:p></o:p></FONT></FONT></FONT></SPAN></P>
<P class=NormalCourierNew style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><FONT size=2><FONT color=#800000><FONT face="Courier New">select i, h, count_big(*) c from dbo.t1, dbo.t2<o:p></o:p></FONT></FONT></FONT></SPAN></P>
<P class=NormalCourierNew style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><FONT size=2><FONT color=#800000><FONT face="Courier New">where j = k<o:p></o:p></FONT></FONT></FONT></SPAN></P>
<P class=NormalCourierNew style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><FONT size=2><FONT color=#800000><FONT face="Courier New">group by i, h<o:p></o:p></FONT></FONT></FONT></SPAN></P>
<P class=NormalCourierNew style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><FONT size=2><FONT color=#800000><FONT face="Courier New">go<o:p></o:p></FONT></FONT></FONT></SPAN></P>
<P class=NormalCourierNew style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><o:p><FONT face="Courier New" color=#800000 size=2>&#160;</FONT></o:p></SPAN></P>
<P class=NormalCourierNew style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><FONT size=2><FONT color=#800000><FONT face="Courier New">create unique clustered index v_ih on v(i, h)<o:p></o:p></FONT></FONT></FONT></SPAN></P>
<P class=NormalCourierNew style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><FONT size=2><FONT color=#800000><FONT face="Courier New">go<o:p></o:p></FONT></FONT></FONT></SPAN></P>
<P class=NormalCourierNew style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><o:p><FONT face="Courier New" color=#800000 size=2>&#160;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt">The changes to either table t1 or t2 need to be propagated to the indexed view v1, in order to keep it consistent at all times. Since the indexed view contains a join and an aggregation in its definition, the Optimizer will automatically augment DML query plans against t1 or t2 with joins and aggregations. Query level hints can be used to influence the join and/or grouping strategy employed by the Optimizer in the query plan.<SPAN style="mso-bidi-font-size: 10.0pt"><o:p></o:p></SPAN></P>
<P class=NormalCourierNew style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><o:p><FONT face="Courier New" color=#800000 size=2>&#160;</FONT></o:p></SPAN></P>
<P class=NormalCourierNew style="MARGIN: 0in 0in 0pt"><FONT size=2><FONT face="Courier New"><SPAN style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><FONT color=#800000>insert into t1 select 1, 2 </FONT></SPAN><B><SPAN style="COLOR: red; mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'">option (hash join, hash group)</SPAN></B><SPAN style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><o:p></o:p></SPAN></FONT></FONT></P>
<P class=NormalCourierNew style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><o:p><FONT face="Courier New" color=#800000 size=2>&#160;</FONT></o:p></SPAN></P>
<P class=NormalCourierNew style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><FONT size=2><FONT color=#800000><FONT face="Courier New"><SPAN style="mso-spacerun: yes">&#160; </SPAN>&#124;--Sequence<o:p></o:p></FONT></FONT></FONT></SPAN></P>
<P class=NormalCourierNew style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><FONT size=2><FONT color=#800000><FONT face="Courier New"><SPAN style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160; </SPAN>&#124;--Table Spool<o:p></o:p></FONT></FONT></FONT></SPAN></P>
<P class=NormalCourierNew style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><FONT size=2><FONT color=#800000><FONT face="Courier New"><SPAN style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160; </SPAN>&#124;<SPAN style="mso-spacerun: yes">&#160;&#160;&#160; </SPAN>&#124;--Table Insert(t1)<o:p></o:p></FONT></FONT></FONT></SPAN></P>
<P class=NormalCourierNew style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><FONT size=2><FONT color=#800000><FONT face="Courier New"><SPAN style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160; </SPAN>&#124;--Clustered Index Update(v)<o:p></o:p></FONT></FONT></FONT></SPAN></P>
<P class=NormalCourierNew style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><FONT size=2><FONT color=#800000><FONT face="Courier New"><SPAN style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </SPAN>&#124;--Collapse<o:p></o:p></FONT></FONT></FONT></SPAN></P>
<P class=NormalCourierNew style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><FONT size=2><FONT color=#800000><FONT face="Courier New"><SPAN style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </SPAN>&#124;--Sort<o:p></o:p></FONT></FONT></FONT></SPAN></P>
<P class=NormalCourierNew style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><FONT size=2><FONT color=#800000><FONT face="Courier New"><SPAN style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </SPAN>&#124;--Compute Scalar<o:p></o:p></FONT></FONT></FONT></SPAN></P>
<P class=NormalCourierNew style="MARGIN: 0in 0in 0pt"><FONT size=2><FONT face="Courier New"><SPAN style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><FONT color=#800000><SPAN style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </SPAN>&#124;--</FONT></SPAN><B><SPAN style="COLOR: red; mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'">Hash Match(Right Outer Join)</SPAN></B><SPAN style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><o:p></o:p></SPAN></FONT></FONT></P>
<P class=NormalCourierNew style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><FONT size=2><FONT color=#800000><FONT face="Courier New"><SPAN style="mso-spacerun: yes">&#160;&#160;&#160; </SPAN><SPAN style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</SPAN>&#124;--Clustered Index Scan(v)<o:p></o:p></FONT></FONT></FONT></SPAN></P>
<P class=NormalCourierNew style="MARGIN: 0in 0in 0pt"><FONT size=2><FONT face="Courier New"><SPAN style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><FONT color=#800000><SPAN style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </SPAN>&#124;--</FONT></SPAN><B><SPAN style="COLOR: red; mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'">Hash Match(Aggregate)</SPAN></B><SPAN style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><o:p></o:p></SPAN></FONT></FONT></P>
<P class=NormalCourierNew style="MARGIN: 0in 0in 0pt"><FONT size=2><FONT face="Courier New"><SPAN style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><FONT color=#800000><SPAN style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </SPAN>&#124;--</FONT></SPAN><B><SPAN style="COLOR: red; mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'">Hash Match(Inner Join)</SPAN></B><SPAN style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><o:p></o:p></SPAN></FONT></FONT></P>
<P class=NormalCourierNew style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><FONT size=2><FONT color=#800000><FONT face="Courier New"><SPAN style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </SPAN>&#124;--Table Spool<o:p></o:p></FONT></FONT></FONT></SPAN></P>
<P class=NormalCourierNew style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><FONT size=2><FONT color=#800000><FONT face="Courier New"><SPAN style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </SPAN><SPAN style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</SPAN>&#124;--Table Scan(t2)<o:p></o:p></FONT></FONT></FONT></SPAN></P>
<P class=NormalCourierNew style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><o:p><FONT face="Courier New" color=#800000 size=2>&#160;</FONT></o:p></SPAN></P>
<P class=NormalCourierNew style="MARGIN: 0in 0in 0pt"><FONT size=2><FONT face="Courier New"><SPAN style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><FONT color=#800000>insert into t1 select 1, 2 </FONT></SPAN><B><SPAN style="COLOR: red; mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'">option (loop join, order group)</SPAN></B><SPAN style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><o:p></o:p></SPAN></FONT></FONT></P>
<P class=NormalCourierNew style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><o:p><FONT face="Courier New" color=#800000 size=2>&#160;</FONT></o:p></SPAN></P>
<P class=NormalCourierNew style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><FONT size=2><FONT color=#800000><FONT face="Courier New"><SPAN style="mso-spacerun: yes">&#160; </SPAN>&#124;--Sequence<o:p></o:p></FONT></FONT></FONT></SPAN></P>
<P class=NormalCourierNew style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><FONT size=2><FONT color=#800000><FONT face="Courier New"><SPAN style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160; </SPAN>&#124;--Table Spool<o:p></o:p></FONT></FONT></FONT></SPAN></P>
<P class=NormalCourierNew style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><FONT size=2><FONT color=#800000><FONT face="Courier New"><SPAN style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160; </SPAN>&#124;<SPAN style="mso-spacerun: yes">&#160;&#160;&#160; </SPAN>&#124;--Table Insert(t1)<o:p></o:p></FONT></FONT></FONT></SPAN></P>
<P class=NormalCourierNew style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><FONT size=2><FONT color=#800000><FONT face="Courier New"><SPAN style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160; </SPAN>&#124;--Clustered Index Update(v)<o:p></o:p></FONT></FONT></FONT></SPAN></P>
<P class=NormalCourierNew style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><FONT size=2><FONT color=#800000><FONT face="Courier New"><SPAN style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </SPAN>&#124;--Collapse<o:p></o:p></FONT></FONT></FONT></SPAN></P>
<P class=NormalCourierNew style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><FONT size=2><FONT color=#800000><FONT face="Courier New"><SPAN style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </SPAN>&#124;--Sort<o:p></o:p></FONT></FONT></FONT></SPAN></P>
<P class=NormalCourierNew style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><FONT size=2><FONT color=#800000><FONT face="Courier New"><SPAN style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </SPAN>&#124;--Compute Scalar<o:p></o:p></FONT></FONT></FONT></SPAN></P>
<P class=NormalCourierNew style="MARGIN: 0in 0in 0pt"><FONT size=2><FONT face="Courier New"><SPAN style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><FONT color=#800000><SPAN style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </SPAN>&#124;--</FONT></SPAN><B><SPAN style="COLOR: red; mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'">Nested Loops(Left Outer Join)</SPAN></B><SPAN style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><o:p></o:p></SPAN></FONT></FONT></P>
<P class=NormalCourierNew style="MARGIN: 0in 0in 0pt"><FONT size=2><FONT face="Courier New"><SPAN style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><FONT color=#800000><SPAN style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </SPAN>&#124;--</FONT></SPAN><B><SPAN style="COLOR: red; mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'">Stream Aggregate</SPAN></B><SPAN style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><o:p></o:p></SPAN></FONT></FONT></P>
<P class=NormalCourierNew style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><FONT size=2><FONT color=#800000><FONT face="Courier New"><SPAN style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </SPAN>&#124;<SPAN style="mso-spacerun: yes">&#160;&#160;&#160; </SPAN>&#124;--Sort<o:p></o:p></FONT></FONT></FONT></SPAN></P>
<P class=NormalCourierNew style="MARGIN: 0in 0in 0pt"><FONT size=2><FONT face="Courier New"><SPAN style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><FONT color=#800000><SPAN style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </SPAN>&#124;<SPAN style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </SPAN>&#124;--</FONT></SPAN><B><SPAN style="COLOR: red; mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'">Nested Loops(Inner Join)<o:p></o:p></SPAN></B></FONT></FONT></P>
<P class=NormalCourierNew style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><FONT size=2><FONT color=#800000><FONT face="Courier New"><SPAN style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </SPAN>&#124;<SPAN style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </SPAN>&#124;--Table Spool<o:p></o:p></FONT></FONT></FONT></SPAN></P>
<P class=NormalCourierNew style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><FONT size=2><FONT color=#800000><FONT face="Courier New"><SPAN style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </SPAN><SPAN style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;</SPAN>&#124;<SPAN style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </SPAN>&#124;--Table Scan(t2)<o:p></o:p></FONT></FONT></FONT></SPAN></P>
<P class=NormalCourierNew style="MARGIN: 0in 0in 0pt"><SPAN style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><FONT size=2><FONT color=#800000><FONT face="Courier New"><SPAN style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </SPAN>&#124;--Clustered Index Seek(v)<o:p></o:p></FONT></FONT></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT face="Courier New" color=#800000 size=2></FONT>&#160;</P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt">Needless to say, query hints are fully documented in Books Online – look for the “Query Hint (Transact-SQL)” topic.</P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><o:p>&#160;</o:p></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt">Ciao,<o:p></o:p></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt">Stefano</P><img src="http://blogs.msdn.com/aggbug.aspx?PostID=666196" width="1" height="1">]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal" style="MARGIN: 0in 0in 0pt">Not everyone knows that query level hints (like loop join) will impact the entirety of a DML query plan. This includes foreign key validation and indexed view maintenance.</p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt">Let us look at an example with two tables involved in a foreign key constraint.</p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-SIZE: 10pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'">use tempdb</span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-SIZE: 10pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'">go</span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-SIZE: 10pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'"> </span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-SIZE: 10pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'">create table department(deptid int primary key clustered, deptname varchar(10))</span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-SIZE: 10pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'">go</span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-SIZE: 10pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'"> </span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-SIZE: 10pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'">create table employee(empid int primary key clustered, empname varchar(10), deptid int references department(deptid))</span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-SIZE: 10pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'">go</span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-SIZE: 10pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'"> </span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-SIZE: 10pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'">insert department values(1, 'Optimizer')</span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-SIZE: 10pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'">go</span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span id="more-202"></span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt">At first glance, it might seem useless to provide a join hint for a scalar insert - like when inserting a row to the employee table – because the query contains no joins. However, this can make sense in presence of foreign key validations, because the Optimizer will automatically augment the query plan with a join for the purpose of validating the constraint. For example, this insert statement here</p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-SIZE: 10pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'">insert employee select 1 empid, 'Stefano' empname, 1 deptid </span><strong style="mso-bidi-font-weight: normal"><span style="FONT-SIZE: 10pt; COLOR: red; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'">option (merge join)</span></strong><span style="FONT-SIZE: 10pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'"> </span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt">will produce a plan with a merge join between the employee and department tables. The join will enforce that the value of the deptid column actually exists in the primary table, department. The “Assert” operator will raise an error if a matching row is not found.</p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-SIZE: 10pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"> </span>|--Assert</span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-SIZE: 10pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"> </span>|--</span><strong style="mso-bidi-font-weight: normal"><span style="FONT-SIZE: 10pt; COLOR: red; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'">Merge Join</span></strong><span style="FONT-SIZE: 10pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'"> </span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-SIZE: 10pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"> </span>|--Clustered Index Insert(employee)</span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-SIZE: 10pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"> </span>|--Clustered Index Scan(department)</span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt">Unfortunately, this technique is restricted to only query (vs. table) level hints, so it's not possible for example to force the indexes being used when accessing the other table involved in the constraint (department in the example). Also, TSQL syntax does not allow specifying query level hints for scalar inserts, like "insert table values...", but the easy workaround is to rewrite the statement as "insert select" like in the example. Update and delete statements do regularly accept query level hints.</p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-SIZE: 10pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'">update employee set empname = 'Conor', deptid = 2 where empid = 1 </span><strong style="mso-bidi-font-weight: normal"><span style="FONT-SIZE: 10pt; COLOR: red; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'">option (loop join)</span></strong><span style="FONT-SIZE: 10pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'"> </span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-SIZE: 10pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'"> </span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-SIZE: 10pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"> </span>|--Assert</span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-SIZE: 10pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"> </span>|--</span><strong><span style="FONT-SIZE: 10pt; COLOR: red; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'">Nested Loops</span></strong><span style="FONT-SIZE: 10pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'"> </span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-SIZE: 10pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"> </span>|--Clustered Index Update(employee)</span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-SIZE: 10pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'"><span style="mso-spacerun: yes"> </span>|--Clustered Index Seek(department)</span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><br style="mso-special-character: line-break" /><br style="mso-special-character: line-break" /></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt">Let us now look at slightly more complex example with an indexed view.</p>
<p class="NormalCourierNew" style="MARGIN: 0in 0in 0pt"><span style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><span style="font-size: x-small;"><span style="color: #800000;"><span style="font-family: Courier New;">use tempdb</span></span></span></span></p>
<p class="NormalCourierNew" style="MARGIN: 0in 0in 0pt"><span style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><span style="font-size: x-small;"><span style="color: #800000;"><span style="font-family: Courier New;">go</span></span></span></span></p>
<p class="NormalCourierNew" style="MARGIN: 0in 0in 0pt"><span style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><span style="font-family: Courier New; color: #800000; font-size: x-small;"> </span></span></p>
<p class="NormalCourierNew" style="MARGIN: 0in 0in 0pt"><span style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><span style="font-size: x-small;"><span style="color: #800000;"><span style="font-family: Courier New;">SET ANSI_NULLS ON</span></span></span></span></p>
<p class="NormalCourierNew" style="MARGIN: 0in 0in 0pt"><span style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><span style="font-size: x-small;"><span style="color: #800000;"><span style="font-family: Courier New;">SET ANSI_PADDING ON</span></span></span></span></p>
<p class="NormalCourierNew" style="MARGIN: 0in 0in 0pt"><span style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><span style="font-size: x-small;"><span style="color: #800000;"><span style="font-family: Courier New;">SET ANSI_WARNINGS ON</span></span></span></span></p>
<p class="NormalCourierNew" style="MARGIN: 0in 0in 0pt"><span style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><span style="font-size: x-small;"><span style="color: #800000;"><span style="font-family: Courier New;">SET CONCAT_NULL_YIELDS_NULL ON</span></span></span></span></p>
<p class="NormalCourierNew" style="MARGIN: 0in 0in 0pt"><span style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><span style="font-size: x-small;"><span style="color: #800000;"><span style="font-family: Courier New;">SET NUMERIC_ROUNDABORT OFF</span></span></span></span></p>
<p class="NormalCourierNew" style="MARGIN: 0in 0in 0pt"><span style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><span style="font-size: x-small;"><span style="color: #800000;"><span style="font-family: Courier New;">SET QUOTED_IDENTIFIER ON</span></span></span></span></p>
<p class="NormalCourierNew" style="MARGIN: 0in 0in 0pt"><span style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><span style="font-size: x-small;"><span style="color: #800000;"><span style="font-family: Courier New;">go</span></span></span></span></p>
<p class="NormalCourierNew" style="MARGIN: 0in 0in 0pt"><span style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><span style="font-size: x-small;"><span style="color: #800000;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes"> </span></span></span></span></span></p>
<p class="NormalCourierNew" style="MARGIN: 0in 0in 0pt"><span style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><span style="font-size: x-small;"><span style="color: #800000;"><span style="font-family: Courier New;">create table t1(i int, j int)</span></span></span></span></p>
<p class="NormalCourierNew" style="MARGIN: 0in 0in 0pt"><span style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><span style="font-size: x-small;"><span style="color: #800000;"><span style="font-family: Courier New;">go</span></span></span></span></p>
<p class="NormalCourierNew" style="MARGIN: 0in 0in 0pt"><span style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><span style="font-family: Courier New; color: #800000; font-size: x-small;"> </span></span></p>
<p class="NormalCourierNew" style="MARGIN: 0in 0in 0pt"><span style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><span style="font-size: x-small;"><span style="color: #800000;"><span style="font-family: Courier New;">create table t2(h int, k int)</span></span></span></span></p>
<p class="NormalCourierNew" style="MARGIN: 0in 0in 0pt"><span style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><span style="font-size: x-small;"><span style="color: #800000;"><span style="font-family: Courier New;">go</span></span></span></span></p>
<p class="NormalCourierNew" style="MARGIN: 0in 0in 0pt"><span style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><span style="font-family: Courier New; color: #800000; font-size: x-small;"> </span></span></p>
<p class="NormalCourierNew" style="MARGIN: 0in 0in 0pt"><span style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><span style="font-size: x-small;"><span style="color: #800000;"><span style="font-family: Courier New;">create view v with schemabinding as</span></span></span></span></p>
<p class="NormalCourierNew" style="MARGIN: 0in 0in 0pt"><span style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><span style="font-size: x-small;"><span style="color: #800000;"><span style="font-family: Courier New;">select i, h, count_big(*) c from dbo.t1, dbo.t2</span></span></span></span></p>
<p class="NormalCourierNew" style="MARGIN: 0in 0in 0pt"><span style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><span style="font-size: x-small;"><span style="color: #800000;"><span style="font-family: Courier New;">where j = k</span></span></span></span></p>
<p class="NormalCourierNew" style="MARGIN: 0in 0in 0pt"><span style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><span style="font-size: x-small;"><span style="color: #800000;"><span style="font-family: Courier New;">group by i, h</span></span></span></span></p>
<p class="NormalCourierNew" style="MARGIN: 0in 0in 0pt"><span style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><span style="font-size: x-small;"><span style="color: #800000;"><span style="font-family: Courier New;">go</span></span></span></span></p>
<p class="NormalCourierNew" style="MARGIN: 0in 0in 0pt"><span style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><span style="font-family: Courier New; color: #800000; font-size: x-small;"> </span></span></p>
<p class="NormalCourierNew" style="MARGIN: 0in 0in 0pt"><span style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><span style="font-size: x-small;"><span style="color: #800000;"><span style="font-family: Courier New;">create unique clustered index v_ih on v(i, h)</span></span></span></span></p>
<p class="NormalCourierNew" style="MARGIN: 0in 0in 0pt"><span style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><span style="font-size: x-small;"><span style="color: #800000;"><span style="font-family: Courier New;">go</span></span></span></span></p>
<p class="NormalCourierNew" style="MARGIN: 0in 0in 0pt"><span style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><span style="font-family: Courier New; color: #800000; font-size: x-small;"> </span></span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt">The changes to either table t1 or t2 need to be propagated to the indexed view v1, in order to keep it consistent at all times. Since the indexed view contains a join and an aggregation in its definition, the Optimizer will automatically augment DML query plans against t1 or t2 with joins and aggregations. Query level hints can be used to influence the join and/or grouping strategy employed by the Optimizer in the query plan.<span style="mso-bidi-font-size: 10.0pt"> </span></p>
<p class="NormalCourierNew" style="MARGIN: 0in 0in 0pt"><span style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><span style="font-family: Courier New; color: #800000; font-size: x-small;"> </span></span></p>
<p class="NormalCourierNew" style="MARGIN: 0in 0in 0pt"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><span style="color: #800000;">insert into t1 select 1, 2 </span></span><strong><span style="COLOR: red; mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'">option (hash join, hash group)</span></strong><span style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"> </span></span></span></p>
<p class="NormalCourierNew" style="MARGIN: 0in 0in 0pt"><span style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><span style="font-family: Courier New; color: #800000; font-size: x-small;"> </span></span></p>
<p class="NormalCourierNew" style="MARGIN: 0in 0in 0pt"><span style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><span style="font-size: x-small;"><span style="color: #800000;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes"> </span>|--Sequence</span></span></span></span></p>
<p class="NormalCourierNew" style="MARGIN: 0in 0in 0pt"><span style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><span style="font-size: x-small;"><span style="color: #800000;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes"> </span>|--Table Spool</span></span></span></span></p>
<p class="NormalCourierNew" style="MARGIN: 0in 0in 0pt"><span style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><span style="font-size: x-small;"><span style="color: #800000;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes"> </span>|<span style="mso-spacerun: yes"> </span>|--Table Insert(t1)</span></span></span></span></p>
<p class="NormalCourierNew" style="MARGIN: 0in 0in 0pt"><span style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><span style="font-size: x-small;"><span style="color: #800000;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes"> </span>|--Clustered Index Update(v)</span></span></span></span></p>
<p class="NormalCourierNew" style="MARGIN: 0in 0in 0pt"><span style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><span style="font-size: x-small;"><span style="color: #800000;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes"> </span>|--Collapse</span></span></span></span></p>
<p class="NormalCourierNew" style="MARGIN: 0in 0in 0pt"><span style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><span style="font-size: x-small;"><span style="color: #800000;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes"> </span>|--Sort</span></span></span></span></p>
<p class="NormalCourierNew" style="MARGIN: 0in 0in 0pt"><span style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><span style="font-size: x-small;"><span style="color: #800000;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes"> </span>|--Compute Scalar</span></span></span></span></p>
<p class="NormalCourierNew" style="MARGIN: 0in 0in 0pt"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><span style="color: #800000;"><span style="mso-spacerun: yes"> </span>|--</span></span><strong><span style="COLOR: red; mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'">Hash Match(Right Outer Join)</span></strong><span style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"> </span></span></span></p>
<p class="NormalCourierNew" style="MARGIN: 0in 0in 0pt"><span style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><span style="font-size: x-small;"><span style="color: #800000;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes"> </span><span style="mso-spacerun: yes"> </span>|--Clustered Index Scan(v)</span></span></span></span></p>
<p class="NormalCourierNew" style="MARGIN: 0in 0in 0pt"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><span style="color: #800000;"><span style="mso-spacerun: yes"> </span>|--</span></span><strong><span style="COLOR: red; mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'">Hash Match(Aggregate)</span></strong><span style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"> </span></span></span></p>
<p class="NormalCourierNew" style="MARGIN: 0in 0in 0pt"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><span style="color: #800000;"><span style="mso-spacerun: yes"> </span>|--</span></span><strong><span style="COLOR: red; mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'">Hash Match(Inner Join)</span></strong><span style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"> </span></span></span></p>
<p class="NormalCourierNew" style="MARGIN: 0in 0in 0pt"><span style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><span style="font-size: x-small;"><span style="color: #800000;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes"> </span>|--Table Spool</span></span></span></span></p>
<p class="NormalCourierNew" style="MARGIN: 0in 0in 0pt"><span style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><span style="font-size: x-small;"><span style="color: #800000;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes"> </span><span style="mso-spacerun: yes"> </span>|--Table Scan(t2)</span></span></span></span></p>
<p class="NormalCourierNew" style="MARGIN: 0in 0in 0pt"><span style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><span style="font-family: Courier New; color: #800000; font-size: x-small;"> </span></span></p>
<p class="NormalCourierNew" style="MARGIN: 0in 0in 0pt"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><span style="color: #800000;">insert into t1 select 1, 2 </span></span><strong><span style="COLOR: red; mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'">option (loop join, order group)</span></strong><span style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"> </span></span></span></p>
<p class="NormalCourierNew" style="MARGIN: 0in 0in 0pt"><span style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><span style="font-family: Courier New; color: #800000; font-size: x-small;"> </span></span></p>
<p class="NormalCourierNew" style="MARGIN: 0in 0in 0pt"><span style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><span style="font-size: x-small;"><span style="color: #800000;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes"> </span>|--Sequence</span></span></span></span></p>
<p class="NormalCourierNew" style="MARGIN: 0in 0in 0pt"><span style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><span style="font-size: x-small;"><span style="color: #800000;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes"> </span>|--Table Spool</span></span></span></span></p>
<p class="NormalCourierNew" style="MARGIN: 0in 0in 0pt"><span style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><span style="font-size: x-small;"><span style="color: #800000;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes"> </span>|<span style="mso-spacerun: yes"> </span>|--Table Insert(t1)</span></span></span></span></p>
<p class="NormalCourierNew" style="MARGIN: 0in 0in 0pt"><span style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><span style="font-size: x-small;"><span style="color: #800000;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes"> </span>|--Clustered Index Update(v)</span></span></span></span></p>
<p class="NormalCourierNew" style="MARGIN: 0in 0in 0pt"><span style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><span style="font-size: x-small;"><span style="color: #800000;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes"> </span>|--Collapse</span></span></span></span></p>
<p class="NormalCourierNew" style="MARGIN: 0in 0in 0pt"><span style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><span style="font-size: x-small;"><span style="color: #800000;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes"> </span>|--Sort</span></span></span></span></p>
<p class="NormalCourierNew" style="MARGIN: 0in 0in 0pt"><span style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><span style="font-size: x-small;"><span style="color: #800000;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes"> </span>|--Compute Scalar</span></span></span></span></p>
<p class="NormalCourierNew" style="MARGIN: 0in 0in 0pt"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><span style="color: #800000;"><span style="mso-spacerun: yes"> </span>|--</span></span><strong><span style="COLOR: red; mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'">Nested Loops(Left Outer Join)</span></strong><span style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"> </span></span></span></p>
<p class="NormalCourierNew" style="MARGIN: 0in 0in 0pt"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><span style="color: #800000;"><span style="mso-spacerun: yes"> </span>|--</span></span><strong><span style="COLOR: red; mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'">Stream Aggregate</span></strong><span style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"> </span></span></span></p>
<p class="NormalCourierNew" style="MARGIN: 0in 0in 0pt"><span style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><span style="font-size: x-small;"><span style="color: #800000;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes"> </span>|<span style="mso-spacerun: yes"> </span>|--Sort</span></span></span></span></p>
<p class="NormalCourierNew" style="MARGIN: 0in 0in 0pt"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><span style="color: #800000;"><span style="mso-spacerun: yes"> </span>|<span style="mso-spacerun: yes"> </span>|--</span></span><strong><span style="COLOR: red; mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'">Nested Loops(Inner Join)</span></strong></span></span></p>
<p class="NormalCourierNew" style="MARGIN: 0in 0in 0pt"><span style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><span style="font-size: x-small;"><span style="color: #800000;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes"> </span>|<span style="mso-spacerun: yes"> </span>|--Table Spool</span></span></span></span></p>
<p class="NormalCourierNew" style="MARGIN: 0in 0in 0pt"><span style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><span style="font-size: x-small;"><span style="color: #800000;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes"> </span><span style="mso-spacerun: yes"> </span>|<span style="mso-spacerun: yes"> </span>|--Table Scan(t2)</span></span></span></span></p>
<p class="NormalCourierNew" style="MARGIN: 0in 0in 0pt"><span style="mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Courier New'"><span style="font-size: x-small;"><span style="color: #800000;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes"> </span>|--Clustered Index Seek(v)</span></span></span></span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="font-family: Courier New; color: #800000; font-size: x-small;"> </span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt">Needless to say, query hints are fully documented in Books Online – look for the “Query Hint (Transact-SQL)” topic.</p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt">Ciao,</p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt">Stefano</p>
Source : http://blogs.msdn.com/queryoptteam/default.aspx]]></content:encoded>
			<wfw:commentRss>http://blogmyquery.com/index.php/2006/07/hints-for-dml-queries/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

