<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>Anthony Bloesch's Web Log</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/anthonybloesch/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/anthonybloesch/feed.xml</link>
    <description>A WebLog about SQL Server development.</description>
    <lastBuildDate>Tue, 16 Apr 2019 04:41:25 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Improvements to Chinese language search in SharePoint</title>
      <link>https://docs.microsoft.com/archive/blogs/anthonybloesch/improvements-to-chinese-language-search-in-sharepoint</link>
      <pubDate>Wed, 29 Nov 2017 03:23:28 GMT</pubDate>
      <dc:creator><![CDATA[Anthony Bloesch]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/anthonybloesch/?p=415</guid>
      <description><![CDATA[There is a longstanding issue with Chinese language search in SharePoint where users got strange...]]></description>
      <content:encoded><![CDATA[There is a longstanding issue with Chinese language search in SharePoint where users got strange results and the summary text highlighting was wrong. Chinese is hard to do word segmentation on (e.g. there is no punctuation character for word separation like the space character in English) and there are issues with neologisms introducing ambiguity. As part of my team's commitment to improving SharePoint for our Chinese customers, we have an experimental project to automatically detect these neologisms and allow customers to add them to SharePoint's custom dictionary. In the process, we found a major cause of poor search results and have made fixes for both SharePoint 2013 and 2016. You can read about it <a href="https://blogs.msdn.microsoft.com/wenhua-ms/2017/11/28/sharepoint-20162013-中文搜索的用户体验的提升-2/">here.</a>]]></content:encoded>
    </item>
    <item>
      <title>On-Premises SharePoint careers</title>
      <link>https://docs.microsoft.com/archive/blogs/anthonybloesch/on-premises-sharepoint-careers</link>
      <pubDate>Fri, 13 Mar 2015 12:03:00 GMT</pubDate>
      <dc:creator><![CDATA[Anthony Bloesch]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/anthonybloesch/2015/03/13/on-premises-sharepoint-careers/</guid>
      <description><![CDATA[I have taken a job as the architect for the new on-premises SharePoint team in Suzhou, China. We are...]]></description>
      <content:encoded><![CDATA[<p>I have taken a job as the architect for the new on-premises SharePoint team in <a href="https://livingsu.com/">Suzhou</a>, China. We are in the process of hiring a large number of engineers. It is a great opportunity for developers and leaders with great distributed systems or database skills. As well as the impact that comes from working on a multibillion dollar product there is a great opportunity to accelerate your career. If you are interested, you can see the positions and apply for them <a href="https://careers.microsoft.com/search.aspx#&amp;&amp;p4=CN&amp;p0=OneDrive+SharePoint&amp;p5=1335&amp;p1=3%2c15&amp;p2=all&amp;p3=1011">here</a>.</p>]]></content:encoded>
    </item>
    <item>
      <title>Bulk loading data with IDataReader and SqlBulkCopy</title>
      <link>https://docs.microsoft.com/archive/blogs/anthonybloesch/bulk-loading-data-with-idatareader-and-sqlbulkcopy</link>
      <pubDate>Wed, 23 Jan 2013 15:23:00 GMT</pubDate>
      <dc:creator><![CDATA[Anthony Bloesch]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/anthonybloesch/2013/01/23/bulk-loading-data-with-idatareader-and-sqlbulkcopy/</guid>
      <description><![CDATA[Introduction
Often large amounts of data need to be quickly loaded into a database. A common...]]></description>
      <content:encoded><![CDATA[<div class="WordSection1">
<h1>Introduction</h1>
<p class="MsoNormal">Often large amounts of data need to be quickly loaded into a database. A common approach is to fill a <a href="https://msdn.microsoft.com/en-us/library/system.data.datatable.aspx">DataTable</a> and use the <a href="https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlbulkcopy.aspx">SqlBulkCopy</a> class to load the data. The problem with this approach is that the data set must be materialized in memory. This is inefficient because the data must be copied and transformed several times and the cache utilization is poor. As well it does not scale because memory is usually a limited resource. But it is far faster than one row at a time inserts.</p>
<p class="MsoNormal">An alternative is to implement an <a href="https://msdn.microsoft.com/en-us/library/system.data.idatareader.aspx">IDataReader</a> and use the SqlBulkCopy class to load the data but the implementation requirements are poorly documented. I have developed the BulkDataReader class that makes the implementation straightforward. With the class, it is possible to stream the data from one source into a database. Since the data has fewer transformations and is streamed from buffer to buffer (and thus utilizes caches better) the performance and resource utilization is much better than other approaches. In practice, the limiting factor with this approach is how fast the data can be read from the data source. In early releases of the .Net Framework, the DataTable approach was much slower than the IDataReader approach but DataTables are now much more efficient and the approaches have comparable performance when memory is not a constraint.</p>
<p class="MsoNormal">Bulk loading data is much faster that loading data with single inserts because the repeated overhead of transferring the data, parsing the insert statement, running the statement and issuing a transaction record is avoided. Instead, a more efficient path is used into the storage engine to stream the data. The setup cost of this path is however much higher than a single insert statement. The break-even point is typically around 10 to 100 rows. Once the data exceeds this size, bulk loading is almost always more efficient.</p>
<p class="MsoNormal">The choice of clustering key, index fill factor and compression has an impact on the time to load large data sets. In general, integer based <a href="https://blogs.msdn.com/b/anthonybloesch/archive/2005/09/09/surrogate-keys.aspx">surrogate keys</a> and sequence objects are the best choices for clustering key. Integer based keys are small and new rows are inserted at the end of the clustered index. This means that SQL Server&rsquo;s lazy writer can write the page once when it is full and more rows fit in a page. By contrast, GUID based and natural keys are inserted non-sequentially and are larger so they require more page writes for the same amount of data. Also, they can cause page splits, which reduces query performance. To minimize the effect of page splits in non-sequential keys, index fill factors should be set to allow some space for growth in index pages (80% is usually a reasonable value). Compression adds CPU overhead to reading and writing data but it often improves overall performance by increasing the number of rows per page and thus reducing the amount of I/O required.</p>
<p class="MsoNormal">Often a heap is used to stage data before inserting it into the target table. This consumes more disk bandwidth but has the advantage that the data loading can be buffered and merges are possible. Typically, a stored procedure runs continuously merging the top <em>n</em> rows into the target table and deleting them from the staging table. Heaps work well for this scenario since enqueue and dequeue operations have low cost.</p>
<p class="MsoNormal">Table partitioning when combined with Windows Server 2012 Storage Spaces can provide a large increase in physical storage bandwidth. But that is too large a topic for this posting. In general, good performance</p>
<h1>BulkDataReader</h1>
<p class="MsoNoSpacing">The download has all the code and test code for the BulkDataReader class. To implement an IDataReader using the BulkDataReader, do the following:</p>
<p class="MsoListBulletCxSpFirst"><span style="font-family: Symbol;">&middot;<span style="font: 7.0pt 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span>Override the SchemaName and TableName properties with meaningful names. These need not match the target schema and table names and are useful for debugging.</p>
<p class="MsoListBulletCxSpMiddle"><span style="font-family: Symbol;">&middot;<span style="font: 7.0pt 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span>Override the AddSchemaTableRows method to declare the schema of the source information. In general, this should match the target schema but some remapping is possible.</p>
<p class="MsoListBulletCxSpMiddle"><span style="font-family: Symbol;">&middot;<span style="font: 7.0pt 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span>Override the GetValue method to return the value of a column for the current row.</p>
<p class="MsoListBulletCxSpMiddle" style="margin-bottom: .0001pt;"><span style="font-family: Symbol;">&middot;<span style="font: 7.0pt 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span>Override the Read method to advance to the next row.</p>
<p class="MsoListBulletCxSpLast" style="margin-bottom: .0001pt;"><span style="font-family: Symbol;">&middot;<span style="font: 7.0pt 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span>If the subclass contains disposable resources, override the dispose method.</p>
<p class="MsoNoSpacing">For example:</p>
<p class="Codenospacing"><span style="color: blue; background: white;">private</span><span style="color: blue; background: white;">class</span><span style="color: #2b91af; background: white;">BulkDataReaderSampleData</span><span style="color: black; background: white;"> : </span><span style="color: #2b91af; background: white;">BulkDataReader</span><span style="color: black; background: white;"><br /> {<br /> &nbsp;&nbsp;&nbsp; </span><span style="color: blue; background: white;">private</span><span style="color: blue; background: white;">string</span><span style="color: black; background: white;"> schemaName;<br /> <br /> &nbsp;&nbsp;&nbsp; </span><span style="color: blue; background: white;">private</span><span style="color: blue; background: white;">string</span><span style="color: black; background: white;"> tableName;<br /> <br /> &nbsp;&nbsp;&nbsp; </span><span style="color: blue; background: white;">private</span><span style="color: blue; background: white;">int</span><span style="color: black; background: white;"> sampleSize;<br /> <br /> &nbsp;&nbsp;&nbsp; </span><span style="color: blue; background: white;">private</span><span style="color: #2b91af; background: white;">SampleValue</span><span style="color: black; background: white;"> sampleValue;<br /> &nbsp;&nbsp;&nbsp; </span><span style="color: blue; background: white;">public</span><span style="color: black; background: white;"> BulkDataReaderSampleData(</span><span style="color: blue; background: white;">string</span><span style="color: black; background: white;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; schemaName,<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue; background: white;">string</span><span style="color: black; background: white;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; tableName,<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue; background: white;">int</span><span style="color: black; background: white;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sampleSize,<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #2b91af; background: white;">SampleValue</span><span style="color: black; background: white;"> sampleValue)<br /> &nbsp;&nbsp;&nbsp; {<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue; background: white;">this</span><span style="color: black; background: white;">.schemaName = schemaName;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue; background: white;">this</span><span style="color: black; background: white;">.tableName = tableName;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue; background: white;">this</span><span style="color: black; background: white;">.sampleSize = sampleSize;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue; background: white;">this</span><span style="color: black; background: white;">.sampleValue = sampleValue;<br /> &nbsp;&nbsp;&nbsp; }<br /> <br /> &nbsp;&nbsp;&nbsp; </span><span style="color: blue; background: white;">protected</span><span style="color: blue; background: white;">override</span><span style="color: blue; background: white;">string</span><span style="color: black; background: white;"> SchemaName<br /> &nbsp;&nbsp;&nbsp; {<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue; background: white;">get</span><span style="color: black; background: white;"> { </span><span style="color: blue; background: white;">return</span><span style="color: blue; background: white;">this</span><span style="color: black; background: white;">.schemaName; }<br /> &nbsp;&nbsp;&nbsp; }<br /> <br /> &nbsp;&nbsp;&nbsp; </span><span style="color: blue; background: white;">protected</span><span style="color: blue; background: white;">override</span><span style="color: blue; background: white;">string</span><span style="color: black; background: white;"> TableName<br /> &nbsp;&nbsp;&nbsp; {<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue; background: white;">get</span><span style="color: black; background: white;"> { </span><span style="color: blue; background: white;">return</span><span style="color: blue; background: white;">this</span><span style="color: black; background: white;">.tableName; }<br /> &nbsp;&nbsp;&nbsp; }<br /> <br /> &nbsp;&nbsp;&nbsp; </span><span style="color: blue; background: white;">protected</span><span style="color: blue; background: white;">override</span><span style="color: blue; background: white;">void</span><span style="color: black; background: white;"> AddSchemaTableRows()<br /> &nbsp;&nbsp;&nbsp; {<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AddSchemaTableRow(</span><span style="color: #a31515; background: white;">"Name"</span><span style="color: black; background: white;">,&nbsp;&nbsp;&nbsp; 100,&nbsp; </span><span style="color: blue; background: white;">null</span><span style="color: black; background: white;">, </span><span style="color: blue; background: white;">null</span><span style="color: black; background: white;">, </span><span style="color: blue; background: white;">true</span><span style="color: black; background: white;">,&nbsp; </span><span style="color: blue; background: white;">false</span><span style="color: black; background: white;">, </span><span style="color: blue; background: white;">false</span><span style="color: black; background: white;">, </span><span style="color: #2b91af; background: white;">SqlDbType</span><span style="color: black; background: white;">.NVarChar, </span><span style="color: blue; background: white;">null</span><span style="color: black; background: white;">, </span><span style="color: blue; background: white;">null</span><span style="color: black; background: white;">, </span><span style="color: blue; background: white;">null</span><span style="color: black; background: white;">, </span><span style="color: blue; background: white;">null</span><span style="color: black; background: white;">, </span><span style="color: blue; background: white;">null</span><span style="color: black; background: white;">);<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AddSchemaTableRow(</span><span style="color: #a31515; background: white;">"DateUtc"</span><span style="color: black; background: white;">, </span><span style="color: blue; background: white;">null</span><span style="color: black; background: white;">, </span><span style="color: blue; background: white;">null</span><span style="color: black; background: white;">, </span><span style="color: blue; background: white;">null</span><span style="color: black; background: white;">, </span><span style="color: blue; background: white;">false</span><span style="color: black; background: white;">, </span><span style="color: blue; background: white;">false</span><span style="color: black; background: white;">, </span><span style="color: blue; background: white;">false</span><span style="color: black; background: white;">, </span><span style="color: #2b91af; background: white;">SqlDbType</span><span style="color: black; background: white;">.DateTime, </span><span style="color: blue; background: white;">null</span><span style="color: black; background: white;">, </span><span style="color: blue; background: white;">null</span><span style="color: black; background: white;">, </span><span style="color: blue; background: white;">null</span><span style="color: black; background: white;">, </span><span style="color: blue; background: white;">null</span><span style="color: black; background: white;">, </span><span style="color: blue; background: white;">null</span><span style="color: black; background: white;">);<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AddSchemaTableRow(</span><span style="color: #a31515; background: white;">"Level"</span><span style="color: black; background: white;">,&nbsp;&nbsp; </span><span style="color: blue; background: white;">null</span><span style="color: black; background: white;">, </span><span style="color: blue; background: white;">null</span><span style="color: black; background: white;">, </span><span style="color: blue; background: white;">null</span><span style="color: black; background: white;">, </span><span style="color: blue; background: white;">false</span><span style="color: black; background: white;">, </span><span style="color: blue; background: white;">false</span><span style="color: black; background: white;">, </span><span style="color: blue; background: white;">false</span><span style="color: black; background: white;">, </span><span style="color: #2b91af; background: white;">SqlDbType</span><span style="color: black; background: white;">.TinyInt,&nbsp; </span><span style="color: blue; background: white;">null</span><span style="color: black; background: white;">, </span><span style="color: blue; background: white;">null</span><span style="color: black; background: white;">, </span><span style="color: blue; background: white;">null</span><span style="color: black; background: white;">, </span><span style="color: blue; background: white;">null</span><span style="color: black; background: white;">, </span><span style="color: blue; background: white;">null</span><span style="color: black; background: white;">);<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AddSchemaTableRow(</span><span style="color: #a31515; background: white;">"Payload"</span><span style="color: black; background: white;">, 1000, </span><span style="color: blue; background: white;">null</span><span style="color: black; background: white;">, </span><span style="color: blue; background: white;">null</span><span style="color: black; background: white;">, </span><span style="color: blue; background: white;">false</span><span style="color: black; background: white;">, </span><span style="color: blue; background: white;">false</span><span style="color: black; background: white;">, </span><span style="color: blue; background: white;">true</span><span style="color: black; background: white;">, </span><span style="color: #2b91af; background: white;">SqlDbType</span><span style="color: black; background: white;">.VarBinary, </span><span style="color: blue; background: white;">null</span><span style="color: black; background: white;">, </span><span style="color: blue; background: white;">null</span><span style="color: black; background: white;">, </span><span style="color: blue; background: white;">null</span><span style="color: black; background: white;">, </span><span style="color: blue; background: white;">null</span><span style="color: black; background: white;">, </span><span style="color: blue; background: white;">null</span><span style="color: black; background: white;">);<br /> &nbsp;&nbsp;&nbsp; }<br /> <br /> &nbsp;&nbsp;&nbsp; </span><span style="color: blue; background: white;">public</span><span style="color: blue; background: white;">override</span><span style="color: blue; background: white;">object</span><span style="color: black; background: white;"> GetValue(</span><span style="color: blue; background: white;">int</span><span style="color: black; background: white;"> i)<br /> &nbsp;&nbsp;&nbsp; {<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue; background: white;">return</span><span style="color: blue; background: white;">this</span><span style="color: black; background: white;">.sampleValue(</span><span style="color: blue; background: white;">this</span><span style="color: black; background: white;">.readCount, i);<br /> &nbsp;&nbsp;&nbsp; }<br /> <br /> &nbsp;&nbsp;&nbsp; </span><span style="color: blue; background: white;">private</span><span style="color: blue; background: white;">int</span><span style="color: black; background: white;"> readCount = 0;<br /> <br /> &nbsp;&nbsp;&nbsp; </span><span style="color: blue; background: white;">public</span><span style="color: blue; background: white;">override</span><span style="color: blue; background: white;">bool</span><span style="color: black; background: white;"> Read()<br /> &nbsp;&nbsp;&nbsp; {<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue; background: white;">return</span><span style="color: black; background: white;"> readCount++ &lt; </span><span style="color: blue; background: white;">this</span><span style="color: black; background: white;">.sampleSize;<br /> &nbsp;&nbsp;&nbsp; }<br /> }</span></p>
<p class="MsoNormal">For brevity the XML document comments have been removed. The download contains more details.</p>
<p class="MsoNoSpacing">To use the BulkDataReader class to load a table with data, use a pattern like:</p>
<p class="Codenospacing"><span style="color: blue; background: white;">using</span><span style="color: black; background: white;"> (</span><span style="background: white;">BulkDataReaderSampleData<span style="color: black;"> bulkReader = </span><span style="color: blue;">new</span>BulkDataReaderSampleData<span style="color: black;">(schemaName,<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tableName,<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sampleSize,<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GetSampleValue))<br /> {<br /> &nbsp;&nbsp;&nbsp; </span>SqlConnectionStringBuilder<span style="color: black;"> connectionString = </span><span style="color: blue;">new</span>SqlConnectionStringBuilder<span style="color: black;">()<br /> &nbsp;&nbsp;&nbsp; {<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ConnectTimeout = 60, </span><span style="color: green;">// 1 minute</span><span style="color: black;"><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; InitialCatalog = databaseName,<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; IntegratedSecurity = </span><span style="color: blue;">true</span><span style="color: black;"><br /> &nbsp;&nbsp;&nbsp; };<br /> <br /> &nbsp;&nbsp;&nbsp; </span><span style="color: blue;">using</span><span style="color: black;"> (</span>SqlConnection<span style="color: black;"> connection = </span><span style="color: blue;">new</span>SqlConnection<span style="color: black;">(connectionString.ConnectionString))<br /> &nbsp;&nbsp;&nbsp; {<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;connection.Open();<br /> <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">using</span><span style="color: black;"> (</span>SqlBulkCopy<span style="color: black;"> bulkCopier = </span><span style="color: blue;">new</span>SqlBulkCopy<span style="color: black;">(connection,<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>SqlBulkCopyOptions<span style="color: black;">.CheckConstraints |<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>SqlBulkCopyOptions<span style="color: black;">.FireTriggers |<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>SqlBulkCopyOptions<span style="color: black;">.KeepNulls |<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>SqlBulkCopyOptions<span style="color: black;">.TableLock |<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>SqlBulkCopyOptions<span style="color: black;">.UseInternalTransaction,<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">null</span><span style="color: black;">))<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">foreach</span><span style="color: black;"> (</span>SqlBulkCopyColumnMapping<span style="color: black;"> mapping </span><span style="color: blue;">in</span><span style="color: black;"> bulkReader.ColumnMappings)<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bulkCopier.ColumnMappings.Add(mapping);<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br /> <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue;">using</span><span style="color: black;"> (</span>SqlCommandBuilder<span style="color: black;"> quoter = </span><span style="color: blue;">new</span>SqlCommandBuilder<span style="color: black;">())<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bulkCopier.DestinationTableName = quoter.QuoteIdentifier(schemaName) + </span><span style="color: #a31515;">"."</span><span style="color: black;"> + quoter.QuoteIdentifier(tableName);<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bulkCopier.BulkCopyTimeout = 60; </span><span style="color: green;">// 1 minute</span><span style="color: black;"><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bulkCopier.BatchSize = 1000;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bulkCopier.EnableStreaming = </span><span style="color: blue;">true</span><span style="color: black;">;<br /> <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bulkCopier.WriteToServer(bulkReader);<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br /> &nbsp;&nbsp;&nbsp; }<br /> }</span></span></p>
<p class="MsoNormal">This is similar to the pattern for a DataTable.</p>
<p class="MsoNormal">Care needs to be taken in the choice of bulk loading options. The choices can noticeably impact overall performance and throughput. The choices in the test code are for a case where multiple data sources are bulk loading data and readers are using snapshot isolation.</p>
<h1>Results</h1>
<p class="MsoNoSpacing">To test the performance implications of various combinations of compression, clustering key types and loading techniques I used the test code in the download to load tables like this:</p>
<p class="Codenospacing"><span style="color: blue; background: white;">create</span><span style="background: white;"> <span style="color: blue;">table</span> [LoadTest]<span style="color: gray;">.</span>[IntKeyCompressed]<br /> <span style="color: gray;">(</span><br /> &nbsp; [Id]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">int</span> <span style="color: gray;">not</span> <span style="color: gray;">null</span><br /> &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue;">constraint</span> [Default_IntKeyCompressed_Id] <span style="color: blue;">default </span><span style="color: gray;">(</span><span style="color: blue;">next</span> value <span style="color: blue;">for</span> [LoadTest]<span style="color: gray;">.</span>[IntKeySequence]<span style="color: gray;">)</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">constraint</span> [PK_IntKeyCompressed] <span style="color: blue;">primary</span> <span style="color: blue;">key</span> <span style="color: blue;">clustered</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">with </span><span style="color: gray;">(</span><span style="color: blue;">fillfactor</span> <span style="color: gray;">=</span> 100<span style="color: gray;">),</span><br /> &nbsp; [Name]&nbsp;&nbsp;&nbsp; <span style="color: blue;">nvarchar</span><span style="color: gray;">(</span>100<span style="color: gray;">)</span> <span style="color: gray;">not</span> <span style="color: gray;">null</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">constraint</span> [Check_IntKeyCompressed_Name_NotEmpty] <span style="color: blue;">check </span><span style="color: gray;">(</span>[Name] <span style="color: gray;">&lt;&gt;</span> <span style="color: red;">N''</span><span style="color: gray;">)</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">constraint</span> [Unique_IntKeyCompressed_Name] <span style="color: blue;">unique</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">with </span><span style="color: gray;">(</span><span style="color: blue;">fillfactor</span> <span style="color: gray;">=</span> 80<span style="color: gray;">,</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">data_compression</span> <span style="color: gray;">=</span> <span style="color: blue;">row</span><span style="color: gray;">),</span><br /> &nbsp; [DateUtc] <span style="color: blue;">datetime2</span> <span style="color: gray;">not</span> <span style="color: gray;">null,</span><br /> &nbsp; [Level]&nbsp;&nbsp; <span style="color: blue;">tinyint</span> <span style="color: gray;">not</span> <span style="color: gray;">null</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">constraint</span> [FK_IntKeyCompressed_Levels_Level] <span style="color: blue;">references</span> [LoadTest]<span style="color: gray;">.</span>[Levels]<span style="color: gray;">(</span>[Id]<span style="color: gray;">),</span><br /> &nbsp; [Payload] <span style="color: blue;">varbinary</span><span style="color: gray;">(</span>1000<span style="color: gray;">)</span> <span style="color: gray;">null</span><br /> <span style="color: gray;">)</span><br /> <span style="color: blue;">with </span><span style="color: gray;">(</span><span style="color: blue;">data_compression</span> <span style="color: gray;">=</span> <span style="color: blue;">row</span><span style="color: gray;">);</span><br /> <br /> <span style="color: blue;">create</span> <span style="color: blue;">index</span> [IX_IntKeyCompressed_Level] <span style="color: blue;">on</span> [LoadTest]<span style="color: gray;">.</span>[IntKeyCompressed]<span style="color: gray;">(</span>[Level]<span style="color: gray;">)</span><br /> &nbsp; <span style="color: blue;">with </span><span style="color: gray;">(</span><span style="color: blue;">fillfactor</span> <span style="color: gray;">=</span> 80<span style="color: gray;">,</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">data_compression</span> <span style="color: gray;">=</span> <span style="color: blue;">row</span><span style="color: gray;">);</span><br /> <br /> <span style="color: blue;">create</span> <span style="color: blue;">index</span> [IX_IntKeyCompressed_DateUtc] <span style="color: blue;">on</span> [LoadTest]<span style="color: gray;">.</span>[IntKeyCompressed]<span style="color: gray;">(</span>[DateUtc]<span style="color: gray;">)</span><br /> &nbsp; <span style="color: blue;">with </span><span style="color: gray;">(</span><span style="color: blue;">fillfactor</span> <span style="color: gray;">=</span> 100<span style="color: gray;">,</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">data_compression</span> <span style="color: gray;">=</span> <span style="color: blue;">row</span><span style="color: gray;">);</span></span></p>
<p class="MsoNormal">The tables approximate event logs. Event logs frequently have high insert volumes. The table also has typical constraints and indexes to correct for the overhead associated with them. <a href="https://msdn.microsoft.com/en-us/library/ms182487.aspx">MSTest</a> was used for timing the runs and to minimize variability. Since the variability was low, only 3 test runs per test case was necessary. The download can be easily modified for other table structures.</p>
<p class="MsoNormal">Table 1 shows the time to load 1&nbsp;000&nbsp;000 rows into an empty table. The SQL Server 2012 database was running in a virtual machine on a workstation so much higher performance can be expected for realistic hardware. For example, a low end database server was able to load 115 692 SharePoint ULS events per second (1&nbsp;000&nbsp;000 rows in 8.6 seconds) using the BulkDataReader. Table 2 shows the time to load 1&nbsp;000&nbsp;000 rows of data into a table with 1&nbsp;000&nbsp;000 rows. The initial table had been rebuilt to simulate normal database maintenance. The natural key based table has one less index since it does not have a surrogate key thus its better performance than the GUID based clustering key.</p>
<p class="MsoCaption" style="page-break-after: avoid;"><a name="_Ref345933896"></a>Table 1: Time, in seconds, to load 1&nbsp;000&nbsp;000 rows of data into an empty table for compressed and uncompressed tables, various clustering key types and various loading techniques. The times are a mean of 3 runs.</p>
<div align="center">
<table class="MsoTableGrid" style="border: currentColor; border-collapse: collapse;" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="border-top: none; border-left: none; border-bottom: solid #F2F2F2 1.0pt; border-right: solid #F2F2F2 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" rowspan="2" valign="top">
<p class="MsoNormal" style="margin-bottom: .0001pt;"><strong>Loader</strong></p>
</td>
<td style="border-top: none; border-left: none; border-bottom: solid #F2F2F2 1.0pt; border-right: solid #F2F2F2 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" colspan="4" valign="top">
<p class="MsoNormal" style="margin-bottom: .0001pt;"><strong>Uncompressed</strong></p>
</td>
<td style="border: none; border-bottom: solid #F2F2F2 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" colspan="4" valign="top">
<p class="MsoNormal" style="margin-bottom: .0001pt;"><strong>Compressed</strong></p>
</td>
</tr>
<tr>
<td style="border-top: none; border-left: none; border-bottom: solid #F2F2F2 1.0pt; border-right: solid #F2F2F2 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="top">
<p class="MsoNormal" style="margin-bottom: .0001pt; text-align: right;" align="right"><strong>Int</strong></p>
</td>
<td style="border: solid #F2F2F2 1.0pt; border-left: none; padding: 0in 5.4pt 0in 5.4pt;" valign="top">
<p class="MsoNormal" style="margin-bottom: .0001pt; text-align: right;" align="right"><strong>GUID</strong></p>
</td>
<td style="border: solid #F2F2F2 1.0pt; border-left: none; padding: 0in 5.4pt 0in 5.4pt;" valign="top">
<p class="MsoNormal" style="margin-bottom: .0001pt; text-align: right;" align="right"><strong>Natural</strong></p>
</td>
<td style="border: solid #F2F2F2 1.0pt; border-left: none; padding: 0in 5.4pt 0in 5.4pt;" valign="top">
<p class="MsoNormal" style="margin-bottom: .0001pt; text-align: right;" align="right"><strong>Heap</strong></p>
</td>
<td style="border-top: none; border-left: none; border-bottom: solid #F2F2F2 1.0pt; border-right: solid #F2F2F2 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="top">
<p class="MsoNormal" style="margin-bottom: .0001pt; text-align: right;" align="right"><strong>Int</strong></p>
</td>
<td style="border-top: none; border-left: none; border-bottom: solid #F2F2F2 1.0pt; border-right: solid #F2F2F2 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="top">
<p class="MsoNormal" style="margin-bottom: .0001pt; text-align: right;" align="right"><strong>GUID</strong></p>
</td>
<td style="border: none; border-bottom: solid #F2F2F2 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="top">
<p class="MsoNormal" style="margin-bottom: .0001pt; text-align: right;" align="right"><strong>Natural</strong></p>
</td>
<td style="border-top: none; border-left: solid #F2F2F2 1.0pt; border-bottom: solid #F2F2F2 1.0pt; border-right: none; padding: 0in 5.4pt 0in 5.4pt;" valign="top">
<p class="MsoNormal" style="margin-bottom: .0001pt; text-align: right;" align="right"><strong>Heap</strong></p>
</td>
</tr>
<tr>
<td style="border: none; border-right: solid #F2F2F2 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="top">
<p class="MsoNormal" style="margin-bottom: .0001pt;">Insert</p>
</td>
<td style="border: none; border-right: solid #F2F2F2 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="bottom">
<p class="MsoNormal" style="margin-bottom: .0001pt; text-align: right;" align="right"><span style="font-family: 'Calibri','sans-serif'; color: black;">2&nbsp;322</span></p>
</td>
<td style="border: none; border-right: solid #F2F2F2 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="bottom">
<p class="MsoNormal" style="margin-bottom: .0001pt; text-align: right;" align="right"><span style="font-family: 'Calibri','sans-serif'; color: black;">4&nbsp;217</span></p>
</td>
<td style="border: none; border-right: solid #F2F2F2 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="bottom">
<p class="MsoNormal" style="margin-bottom: .0001pt; text-align: right;" align="right"><span style="font-family: 'Calibri','sans-serif'; color: black;">3&nbsp;592</span></p>
</td>
<td style="border: none; border-right: solid #F2F2F2 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="bottom">
<p class="MsoNormal" style="margin-bottom: .0001pt; text-align: right;" align="right"><span style="font-family: 'Calibri','sans-serif'; color: black;">1&nbsp;764</span></p>
</td>
<td style="border: none; border-right: solid #F2F2F2 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="bottom">
<p class="MsoNormal" style="margin-bottom: .0001pt; text-align: right;" align="right"><span style="font-family: 'Calibri','sans-serif'; color: black;">2&nbsp;152</span></p>
</td>
<td style="border: none; border-right: solid #F2F2F2 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="bottom">
<p class="MsoNormal" style="margin-bottom: .0001pt; text-align: right;" align="right"><span style="font-family: 'Calibri','sans-serif'; color: black;">7&nbsp;817</span></p>
</td>
<td style="border: none; padding: 0in 5.4pt 0in 5.4pt;" valign="bottom">
<p class="MsoNormal" style="margin-bottom: .0001pt; text-align: right;" align="right"><span style="font-family: 'Calibri','sans-serif'; color: black;">2&nbsp;952</span></p>
</td>
<td style="border: none; border-left: solid #F2F2F2 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="bottom">
<p class="MsoNormal" style="margin-bottom: .0001pt; text-align: right;" align="right"><span style="font-family: 'Calibri','sans-serif'; color: black;">1&nbsp;715</span></p>
</td>
</tr>
<tr>
<td style="border: none; border-right: solid #F2F2F2 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="top">
<p class="MsoNormal" style="margin-bottom: .0001pt;">DataTable</p>
</td>
<td style="border: none; border-right: solid #F2F2F2 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="bottom">
<p class="MsoNormal" style="margin-bottom: .0001pt; text-align: right;" align="right"><span style="font-family: 'Calibri','sans-serif'; color: black;">147</span></p>
</td>
<td style="border: none; border-right: solid #F2F2F2 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="bottom">
<p class="MsoNormal" style="margin-bottom: .0001pt; text-align: right;" align="right"><span style="font-family: 'Calibri','sans-serif'; color: black;">239</span></p>
</td>
<td style="border: none; border-right: solid #F2F2F2 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="bottom">
<p class="MsoNormal" style="margin-bottom: .0001pt; text-align: right;" align="right"><span style="font-family: 'Calibri','sans-serif'; color: black;">205</span></p>
</td>
<td style="border: none; border-right: solid #F2F2F2 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="bottom">
<p class="MsoNormal" style="margin-bottom: .0001pt; text-align: right;" align="right"><span style="font-family: 'Calibri','sans-serif'; color: black;">69</span></p>
</td>
<td style="border: none; border-right: solid #F2F2F2 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="bottom">
<p class="MsoNormal" style="margin-bottom: .0001pt; text-align: right;" align="right"><span style="font-family: 'Calibri','sans-serif'; color: black;">137</span></p>
</td>
<td style="border: none; border-right: solid #F2F2F2 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="bottom">
<p class="MsoNormal" style="margin-bottom: .0001pt; text-align: right;" align="right"><span style="font-family: 'Calibri','sans-serif'; color: black;">329</span></p>
</td>
<td style="border: none; padding: 0in 5.4pt 0in 5.4pt;" valign="bottom">
<p class="MsoNormal" style="margin-bottom: .0001pt; text-align: right;" align="right"><span style="font-family: 'Calibri','sans-serif'; color: black;">166</span></p>
</td>
<td style="border: none; border-left: solid #F2F2F2 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="bottom">
<p class="MsoNormal" style="margin-bottom: .0001pt; text-align: right;" align="right"><span style="font-family: 'Calibri','sans-serif'; color: black;">77</span></p>
</td>
</tr>
<tr>
<td style="border: none; border-right: solid #F2F2F2 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="top">
<p class="MsoNormal" style="margin-bottom: .0001pt;">BulkDataReader</p>
</td>
<td style="border: none; border-right: solid #F2F2F2 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="bottom">
<p class="MsoNormal" style="margin-bottom: .0001pt; text-align: right;" align="right"><span style="font-family: 'Calibri','sans-serif'; color: black;">142</span></p>
</td>
<td style="border: none; border-right: solid #F2F2F2 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="bottom">
<p class="MsoNormal" style="margin-bottom: .0001pt; text-align: right;" align="right"><span style="font-family: 'Calibri','sans-serif'; color: black;">238</span></p>
</td>
<td style="border: none; border-right: solid #F2F2F2 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="bottom">
<p class="MsoNormal" style="margin-bottom: .0001pt; text-align: right;" align="right"><span style="font-family: 'Calibri','sans-serif'; color: black;">207</span></p>
</td>
<td style="border: none; border-right: solid #F2F2F2 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="bottom">
<p class="MsoNormal" style="margin-bottom: .0001pt; text-align: right;" align="right"><span style="font-family: 'Calibri','sans-serif'; color: black;">61</span></p>
</td>
<td style="border: none; border-right: solid #F2F2F2 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="bottom">
<p class="MsoNormal" style="margin-bottom: .0001pt; text-align: right;" align="right"><span style="font-family: 'Calibri','sans-serif'; color: black;">127</span></p>
</td>
<td style="border: none; border-right: solid #F2F2F2 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="bottom">
<p class="MsoNormal" style="margin-bottom: .0001pt; text-align: right;" align="right"><span style="font-family: 'Calibri','sans-serif'; color: black;">313</span></p>
</td>
<td style="border: none; padding: 0in 5.4pt 0in 5.4pt;" valign="bottom">
<p class="MsoNormal" style="margin-bottom: .0001pt; text-align: right;" align="right"><span style="font-family: 'Calibri','sans-serif'; color: black;">164</span></p>
</td>
<td style="border: none; border-left: solid #F2F2F2 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="bottom">
<p class="MsoNormal" style="margin-bottom: .0001pt; text-align: right;" align="right"><span style="font-family: 'Calibri','sans-serif'; color: black;">68</span></p>
</td>
</tr>
</tbody>
</table>
</div>
<p class="MsoNormal">&nbsp;</p>
<p class="MsoCaption" style="page-break-after: avoid;"><a name="_Ref345934316"></a>Table 2: Time, in seconds, to load 1&nbsp;000&nbsp;000 rows of data into a table with 1&nbsp;000&nbsp;000 rows for compressed and uncompressed tables, various clustering key types and various loading techniques. The times are a mean of 3 runs.</p>
<div align="center">
<table class="MsoTableGrid" style="border: currentColor; border-collapse: collapse;" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="border-top: none; border-left: none; border-bottom: solid #F2F2F2 1.0pt; border-right: solid #F2F2F2 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" rowspan="2" valign="top">
<p class="MsoNormal" style="margin-bottom: .0001pt;"><strong>Loader</strong></p>
</td>
<td style="border-top: none; border-left: none; border-bottom: solid #F2F2F2 1.0pt; border-right: solid #F2F2F2 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" colspan="4" valign="top">
<p class="MsoNormal" style="margin-bottom: .0001pt;"><strong>Uncompressed</strong></p>
</td>
<td style="border: none; border-bottom: solid #F2F2F2 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" colspan="4" valign="top">
<p class="MsoNormal" style="margin-bottom: .0001pt;"><strong>Compressed</strong></p>
</td>
</tr>
<tr>
<td style="border-top: none; border-left: none; border-bottom: solid #F2F2F2 1.0pt; border-right: solid #F2F2F2 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="top">
<p class="MsoNormal" style="margin-bottom: .0001pt; text-align: right;" align="right"><strong>Int</strong></p>
</td>
<td style="border: solid #F2F2F2 1.0pt; border-left: none; padding: 0in 5.4pt 0in 5.4pt;" valign="top">
<p class="MsoNormal" style="margin-bottom: .0001pt; text-align: right;" align="right"><strong>GUID</strong></p>
</td>
<td style="border: solid #F2F2F2 1.0pt; border-left: none; padding: 0in 5.4pt 0in 5.4pt;" valign="top">
<p class="MsoNormal" style="margin-bottom: .0001pt; text-align: right;" align="right"><strong>Natural</strong></p>
</td>
<td style="border: solid #F2F2F2 1.0pt; border-left: none; padding: 0in 5.4pt 0in 5.4pt;" valign="top">
<p class="MsoNormal" style="margin-bottom: .0001pt; text-align: right;" align="right"><strong>Heap</strong></p>
</td>
<td style="border-top: none; border-left: none; border-bottom: solid #F2F2F2 1.0pt; border-right: solid #F2F2F2 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="top">
<p class="MsoNormal" style="margin-bottom: .0001pt; text-align: right;" align="right"><strong>Int</strong></p>
</td>
<td style="border-top: none; border-left: none; border-bottom: solid #F2F2F2 1.0pt; border-right: solid #F2F2F2 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="top">
<p class="MsoNormal" style="margin-bottom: .0001pt; text-align: right;" align="right"><strong>GUID</strong></p>
</td>
<td style="border: none; border-bottom: solid #F2F2F2 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="top">
<p class="MsoNormal" style="margin-bottom: .0001pt; text-align: right;" align="right"><strong>Natural</strong></p>
</td>
<td style="border-top: none; border-left: solid #F2F2F2 1.0pt; border-bottom: solid #F2F2F2 1.0pt; border-right: none; padding: 0in 5.4pt 0in 5.4pt;" valign="top">
<p class="MsoNormal" style="margin-bottom: .0001pt; text-align: right;" align="right"><strong>Heap</strong></p>
</td>
</tr>
<tr>
<td style="border: none; border-right: solid #F2F2F2 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="top">
<p class="MsoNormal" style="margin-bottom: .0001pt;">Insert</p>
</td>
<td style="border: none; border-right: solid #F2F2F2 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="bottom">
<p class="MsoNormal" style="margin-bottom: .0001pt; text-align: right;" align="right"><span style="font-family: 'Calibri','sans-serif'; color: black;">2&nbsp;834</span></p>
</td>
<td style="border: none; border-right: solid #F2F2F2 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="bottom">
<p class="MsoNormal" style="margin-bottom: .0001pt; text-align: right;" align="right"><span style="font-family: 'Calibri','sans-serif'; color: black;">6&nbsp;043</span></p>
</td>
<td style="border: none; border-right: solid #F2F2F2 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="bottom">
<p class="MsoNormal" style="margin-bottom: .0001pt; text-align: right;" align="right"><span style="font-family: 'Calibri','sans-serif'; color: black;">4&nbsp;589</span></p>
</td>
<td style="border: none; border-right: solid #F2F2F2 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="bottom">
<p class="MsoNormal" style="margin-bottom: .0001pt; text-align: right;" align="right"><span style="font-family: 'Calibri','sans-serif'; color: black;">1&nbsp;591</span></p>
</td>
<td style="border: none; border-right: solid #F2F2F2 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="bottom">
<p class="MsoNormal" style="margin-bottom: .0001pt; text-align: right;" align="right"><span style="font-family: 'Calibri','sans-serif'; color: black;">2&nbsp;699</span></p>
</td>
<td style="border: none; border-right: solid #F2F2F2 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="bottom">
<p class="MsoNormal" style="margin-bottom: .0001pt; text-align: right;" align="right"><span style="font-family: 'Calibri','sans-serif'; color: black;">7&nbsp;886</span></p>
</td>
<td style="border: none; padding: 0in 5.4pt 0in 5.4pt;" valign="bottom">
<p class="MsoNormal" style="margin-bottom: .0001pt; text-align: right;" align="right"><span style="font-family: 'Calibri','sans-serif'; color: black;">3&nbsp;948</span></p>
</td>
<td style="border: none; border-left: solid #F2F2F2 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="bottom">
<p class="MsoNormal" style="margin-bottom: .0001pt; text-align: right;" align="right"><span style="font-family: 'Calibri','sans-serif'; color: black;">1&nbsp;554</span></p>
</td>
</tr>
<tr>
<td style="border: none; border-right: solid #F2F2F2 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="top">
<p class="MsoNormal" style="margin-bottom: .0001pt;">DataTable</p>
</td>
<td style="border: none; border-right: solid #F2F2F2 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="bottom">
<p class="MsoNormal" style="margin-bottom: .0001pt; text-align: right;" align="right"><span style="font-family: 'Calibri','sans-serif'; color: black;">164</span></p>
</td>
<td style="border: none; border-right: solid #F2F2F2 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="bottom">
<p class="MsoNormal" style="margin-bottom: .0001pt; text-align: right;" align="right"><span style="font-family: 'Calibri','sans-serif'; color: black;">286</span></p>
</td>
<td style="border: none; border-right: solid #F2F2F2 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="bottom">
<p class="MsoNormal" style="margin-bottom: .0001pt; text-align: right;" align="right"><span style="font-family: 'Calibri','sans-serif'; color: black;">287</span></p>
</td>
<td style="border: none; border-right: solid #F2F2F2 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="bottom">
<p class="MsoNormal" style="margin-bottom: .0001pt; text-align: right;" align="right"><span style="font-family: 'Calibri','sans-serif'; color: black;">68</span></p>
</td>
<td style="border: none; border-right: solid #F2F2F2 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="bottom">
<p class="MsoNormal" style="margin-bottom: .0001pt; text-align: right;" align="right"><span style="font-family: 'Calibri','sans-serif'; color: black;">151</span></p>
</td>
<td style="border: none; border-right: solid #F2F2F2 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="bottom">
<p class="MsoNormal" style="margin-bottom: .0001pt; text-align: right;" align="right"><span style="font-family: 'Calibri','sans-serif'; color: black;">336</span></p>
</td>
<td style="border: none; padding: 0in 5.4pt 0in 5.4pt;" valign="bottom">
<p class="MsoNormal" style="margin-bottom: .0001pt; text-align: right;" align="right"><span style="font-family: 'Calibri','sans-serif'; color: black;">198</span></p>
</td>
<td style="border: none; border-left: solid #F2F2F2 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="bottom">
<p class="MsoNormal" style="margin-bottom: .0001pt; text-align: right;" align="right"><span style="font-family: 'Calibri','sans-serif'; color: black;">91</span></p>
</td>
</tr>
<tr>
<td style="border: none; border-right: solid #F2F2F2 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="top">
<p class="MsoNormal" style="margin-bottom: .0001pt;">BulkDataReader</p>
</td>
<td style="border: none; border-right: solid #F2F2F2 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="bottom">
<p class="MsoNormal" style="margin-bottom: .0001pt; text-align: right;" align="right"><span style="font-family: 'Calibri','sans-serif'; color: black;">160</span></p>
</td>
<td style="border: none; border-right: solid #F2F2F2 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="bottom">
<p class="MsoNormal" style="margin-bottom: .0001pt; text-align: right;" align="right"><span style="font-family: 'Calibri','sans-serif'; color: black;">258</span></p>
</td>
<td style="border: none; border-right: solid #F2F2F2 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="bottom">
<p class="MsoNormal" style="margin-bottom: .0001pt; text-align: right;" align="right"><span style="font-family: 'Calibri','sans-serif'; color: black;">269</span></p>
</td>
<td style="border: none; border-right: solid #F2F2F2 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="bottom">
<p class="MsoNormal" style="margin-bottom: .0001pt; text-align: right;" align="right"><span style="font-family: 'Calibri','sans-serif'; color: black;">95</span></p>
</td>
<td style="border: none; border-right: solid #F2F2F2 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="bottom">
<p class="MsoNormal" style="margin-bottom: .0001pt; text-align: right;" align="right"><span style="font-family: 'Calibri','sans-serif'; color: black;">140</span></p>
</td>
<td style="border: none; border-right: solid #F2F2F2 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="bottom">
<p class="MsoNormal" style="margin-bottom: .0001pt; text-align: right;" align="right"><span style="font-family: 'Calibri','sans-serif'; color: black;">301</span></p>
</td>
<td style="border: none; padding: 0in 5.4pt 0in 5.4pt;" valign="bottom">
<p class="MsoNormal" style="margin-bottom: .0001pt; text-align: right;" align="right"><span style="font-family: 'Calibri','sans-serif'; color: black;">189</span></p>
</td>
<td style="border: none; border-left: solid #F2F2F2 1.0pt; padding: 0in 5.4pt 0in 5.4pt;" valign="bottom">
<p class="MsoNormal" style="margin-bottom: .0001pt; text-align: right;" align="right"><span style="font-family: 'Calibri','sans-serif'; color: black;">52</span></p>
</td>
</tr>
</tbody>
</table>
</div>
<p class="MsoNormal">&nbsp;</p>
<p class="MsoNormal">As expected, bulk loading data is more efficient than single inserts, integer based surrogate keys are more efficient than alternatives and heaps are an efficient way to stage data.</p>
<h1>Download</h1>
<p class="MsoNoSpacing">The download is a Visual Studio 2012 solution. It contains:</p>
<p class="MsoListBulletCxSpFirst"><span style="font-family: Symbol;">&middot;<span style="font: 7.0pt 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span>The DataUtilities C<sup>#</sup> project contains the code for the BulkDataReader class.</p>
<p class="MsoListBulletCxSpMiddle"><span style="font-family: Symbol;">&middot;<span style="font: 7.0pt 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span>The DataUtilitiesTest C<sup>#</sup> test project contains the test code for the correctness of the BulkDataReader class and performance tests.</p>
<p class="MsoListBulletCxSpLast"><span style="font-family: Symbol;">&middot;<span style="font: 7.0pt 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span>The TestDatabase SQL Server database project contains the definition of the test tables.</p>
</div>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Components.PostAttachments/00/10/38/77/48/FastLoader.zip" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-components-postattachments/00-10-38-77-48/FastLoader.zip">FastLoader.zip</a></p>]]></content:encoded>
    </item>
    <item>
      <title>Finding and stopping rogue SQL traces</title>
      <link>https://docs.microsoft.com/archive/blogs/anthonybloesch/finding-and-stopping-rogue-sql-traces</link>
      <pubDate>Fri, 14 Dec 2012 13:44:00 GMT</pubDate>
      <dc:creator><![CDATA[Anthony Bloesch]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/anthonybloesch/2012/12/14/finding-and-stopping-rogue-sql-traces/</guid>
      <description><![CDATA[Introduction
A common cause of mysterious performance issues are traces that have been left...]]></description>
      <content:encoded><![CDATA[<div class="WordSection1">
<h1>Introduction</h1>
<p class="MsoNormal">A common cause of mysterious performance issues are traces that have been left running. Na&iuml;ve use of traces can leave many traces running&mdash;traces that are slowing down the application by consuming critical resources. This happens because the SQL Server Performance Analyzer process is killed or trace sessions forgotten. In analyzing an issue, many traces may be created and left running.</p>
<h1>Scripts</h1>
<p class="MsoNoSpacing">I see this issue enough that I have created some scripts for the issue. The following query will tell you which non-default traces exist:</p>
<p class="Codenospacing"><span style="color: blue;">use</span> [master]<br /> <br /> <span style="color: blue;">select</span> T<span style="color: gray;">.</span>id <span style="color: blue;">as</span> [Id]<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">case</span> T<span style="color: gray;">.</span><span style="color: blue;">status</span> <span style="color: blue;">when</span> 0 <span style="color: blue;">then</span> <span style="color: red;">N'stopped'</span> <span style="color: blue;">else</span> <span style="color: red;">N'running'</span> <span style="color: blue;">end</span> <span style="color: blue;">as</span> [Status]<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; T<span style="color: gray;">.</span><span style="color: blue;">path</span> <span style="color: blue;">as</span> [Path]<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">case</span> T<span style="color: gray;">.</span>is_rowset <span style="color: blue;">when</span> 0 <span style="color: blue;">then</span> <span style="color: red;">N'false'</span> <span style="color: blue;">else</span> <span style="color: red;">N'true'</span> <span style="color: blue;">end</span> <span style="color: blue;">as</span> [Rowset]<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">case</span> T<span style="color: gray;">.</span>is_shutdown <span style="color: blue;">when</span> 0 <span style="color: blue;">then</span> <span style="color: red;">N'disabled'</span> <span style="color: blue;">else</span> <span style="color: red;">N'enabled'</span> <span style="color: blue;">end</span> <span style="color: blue;">as</span> [Shutdown option]<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; T<span style="color: gray;">.</span>start_time <span style="color: blue;">as</span> [Start]<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; T<span style="color: gray;">.</span>stop_time <span style="color: blue;">as</span> [Stop]<br /> <span style="color: blue;">from</span> <span style="color: green;">sys</span><span style="color: gray;">.</span><span style="color: green;">traces</span> <span style="color: blue;">as</span> T<br /> <span style="color: blue;">where</span> T<span style="color: gray;">.</span>is_default <span style="color: gray;">&lt;&gt;</span> 1<span style="color: gray;">;</span></p>
<p class="MsoNoSpacing">The following query can be used to close all non-default traces it also lists their locations.</p>
<p class="Codenospacing"><span style="color: blue;">use</span> [master]<span style="color: gray;">;<br /> <br /> </span><span style="color: blue;">set</span> <span style="color: blue;">nocount</span> <span style="color: blue;">on</span><span style="color: gray;">;<br /> <br /> </span><span style="color: blue;">declare</span> @result <span style="color: blue;">table </span><span style="color: gray;">(</span>[Path] <span style="color: blue;">nvarchar</span><span style="color: gray;">(</span>260<span style="color: gray;">)</span> <span style="color: gray;">not</span> <span style="color: gray;">null);<br /> <br /> </span><span style="color: blue;">declare</span> trace <span style="color: blue;">cursor</span> <span style="color: blue;">local</span> <span style="color: blue;">fast_forward</span> <span style="color: blue;">for</span> <span style="color: blue;">select</span> T<span style="color: gray;">.</span>id<span style="color: gray;">,</span> T<span style="color: gray;">.</span><span style="color: blue;">path<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">from</span> <span style="color: green;">sys</span><span style="color: gray;">.</span><span style="color: green;">traces</span> <span style="color: blue;">as</span> T<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">where</span> T<span style="color: gray;">.</span>is_default <span style="color: gray;">!=</span> 1<span style="color: gray;">;<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /> <span style="color: blue;">open</span> trace<span style="color: gray;">;<br /> <br /> </span><span style="color: blue;">declare</span> @id <span style="color: blue;">int</span><span style="color: gray;">;<br /> </span><span style="color: blue;">declare</span> @path <span style="color: blue;">nvarchar</span><span style="color: gray;">(</span>260<span style="color: gray;">);<br /> <br /> </span><span style="color: blue;">fetch</span> <span style="color: blue;">next</span> <span style="color: blue;">from</span> trace<br /> &nbsp; <span style="color: blue;">into</span> @id<span style="color: gray;">,</span> @path<span style="color: gray;">;<br /> </span>&nbsp; <br /> <span style="color: blue;">while</span> <span style="color: fuchsia;">@@fetch_status</span> <span style="color: gray;">=</span> 0<br /> <span style="color: blue;">begin<br /> </span>&nbsp;&nbsp; <span style="color: blue;">execute</span> <span style="color: maroon;">sp_trace_setstatus<br /> </span><span style="color: blue;">&nbsp;&nbsp;&nbsp;&nbsp; </span>@traceid <span style="color: gray;">=</span> @id<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp; @status <span style="color: gray;">=</span> 0<span style="color: gray;">;<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp; <br /> &nbsp;&nbsp; <span style="color: blue;">execute</span> <span style="color: maroon;">sp_trace_setstatus<br /> </span><span style="color: blue;">&nbsp;&nbsp;&nbsp;&nbsp; </span>@traceid <span style="color: gray;">=</span> @id<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp; @status <span style="color: gray;">=</span> 2<span style="color: gray;">;<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp; <br /> &nbsp;&nbsp; <span style="color: blue;">if </span><span style="color: gray;">(</span>@path <span style="color: gray;">is</span> <span style="color: gray;">not</span> <span style="color: gray;">null)<br /> </span>&nbsp;&nbsp; <span style="color: blue;">begin<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">insert</span> <span style="color: blue;">into</span> @result<span style="color: gray;">(</span>[Path]<span style="color: gray;">)<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">values </span><span style="color: gray;">(</span>@path<span style="color: gray;">);<br /> </span>&nbsp;&nbsp; <span style="color: blue;">end</span><span style="color: gray;">;<br /> <br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">fetch</span> <span style="color: blue;">next</span> <span style="color: blue;">from</span> trace<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; <span style="color: blue;">into</span> @id<span style="color: gray;">,</span> @path<span style="color: gray;">;<br /> </span><span style="color: blue;">end</span><span style="color: gray;">;<br /> <br /> </span><span style="color: blue;">close</span> trace<span style="color: gray;">;<br /> </span><span style="color: blue;">deallocate</span> trace<span style="color: gray;">;<br /> <br /> </span><span style="color: blue;">select</span> R<span style="color: gray;">.</span>[Path] <span style="color: blue;">as</span> [Path]<br /> <span style="color: blue;">from</span> @result <span style="color: blue;">as</span> R<span style="color: gray;">;</span></p>
<p class="MsoNoSpacing">In general, the queries require view server state permission:</p>
<p class="Codenospacing"><span style="color: blue;">grant</span> <span style="color: blue;">alter trace</span> <span style="color: blue;">to</span> [login name]<span style="color: gray;">;</span></p>
</div>]]></content:encoded>
    </item>
    <item>
      <title>SQL Server performance investigation</title>
      <link>https://docs.microsoft.com/archive/blogs/anthonybloesch/sql-server-performance-investigation</link>
      <pubDate>Fri, 07 Dec 2012 15:13:00 GMT</pubDate>
      <dc:creator><![CDATA[Anthony Bloesch]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/anthonybloesch/2012/12/07/sql-server-performance-investigation/</guid>
      <description><![CDATA[Introduction
I frequently help teams inside and outside of Microsoft investigate SQL Server...]]></description>
      <content:encoded><![CDATA[<div class="WordSection1">
<h1>Introduction</h1>
<p class="MsoNormal">I frequently help teams inside and outside of Microsoft investigate SQL Server database performance issues. As well, I monitor some large internal SharePoint databases to understand their performance characteristics and to make sure we are improving our overall performance. Here are some of the queries I use to investigate performance issues and monitor performance. I hope you will find them useful.</p>
<p class="MsoNormal">SQL Server provides an extensive list of views and functions that are useful for understanding the internal behavior of SQL Server (see <em>Microsoft SQL Server 2008 Internals</em> by Kalen Delaney <em>et al</em> for a good explanation of SQL Server&rsquo;s internals). Performance issues manifest themselves as excessive use of some system resource. In most applications, the resources of interest are memory and CPU. These are of interest in SQL Server but also of interest are resources like locks, latches and storage bandwidth.</p>
<p class="MsoNormal">Most SQL Server resources are managed at the SQL Server instance level. In general, a SQL Server instance should correspond to a single application. Thus the queries below work at the SQL Server level. Where sensible, I have added a commented out line that will scope the query to the current database.</p>
<p class="MsoNormal">Performance analysis and improvements is a tradeoff. It may not be cost effective to fix minor issues. Thus the queries below focus on highlighting the significant issues.</p>
<p class="MsoNoSpacing">In general, the queries require view server state permission:</p>
<p class="Codenospacing"><span style="color: blue;">grant</span> <span style="color: blue;">view</span> <span style="color: blue;">server</span> <span style="color: blue;">state</span> <span style="color: blue;">to</span> [login name]<span style="color: gray;">;</span></p>
<h1>Storage operations</h1>
<p class="MsoNormal">SQL Server applications are frequently limited by disk bandwidth. Whenever SQL Server reads a data page that is called a logical read. When the page is not in memory and thus must be read from disk that is called a physical read. The situation is slightly different for writes. Whenever SQL Server changes a data page that is called a logical write. However, the page is not immediately written to disk. Instead it is queued and the lazy writer will eventually write it to disk. Since the page may be modified by several T-SQL statements before it is written to disk, a single T-SQL statement cannot be directly associated with the write. For example, code that appends rows to the end of a table may make many logical writes but cause relatively few physical writes.</p>
<h2>Module logical reads</h2>
<p class="MsoNoSpacing">Here is a query to find the modules (i.e. procedures and triggers) with the highest logical read volumes.</p>
<p class="Codenospacing"><span style="color: blue;">select</span> <span style="color: blue;">top</span><span style="color: gray;">(</span>10<span style="color: gray;">)</span> D<span style="color: gray;">.</span>total_physical_reads <span style="color: blue;">as</span> [Total physical reads]<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; D<span style="color: gray;">.</span>total_logical_reads <span style="color: blue;">as</span> [Total logical reads]<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; D<span style="color: gray;">.</span>execution_count <span style="color: blue;">as</span> [Executions]<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: fuchsia;">coalesce</span><span style="color: gray;">(</span><span style="color: fuchsia;">quotename</span><span style="color: gray;">(</span><span style="color: fuchsia;">db_name</span><span style="color: gray;">(</span>D<span style="color: gray;">.</span>database_id<span style="color: gray;">)),</span> <span style="color: red;">N'-'</span><span style="color: gray;">)</span> <span style="color: gray;">+</span> <span style="color: red;">N'.'</span> <span style="color: gray;">+</span> <span style="color: fuchsia;">coalesce</span><span style="color: gray;">(</span><span style="color: fuchsia;">quotename</span><span style="color: gray;">(</span><span style="color: fuchsia;">object_schema_name</span><span style="color: gray;">(</span>D<span style="color: gray;">.</span><span style="color: fuchsia;">object_id</span><span style="color: gray;">,</span> D<span style="color: gray;">.</span>database_id<span style="color: gray;">)),</span> <span style="color: red;">N'-'</span><span style="color: gray;">)</span> <span style="color: gray;">+</span> <span style="color: red;">N'.'</span> <span style="color: gray;">+</span> <span style="color: fuchsia;">coalesce</span><span style="color: gray;">(</span><span style="color: fuchsia;">quotename</span><span style="color: gray;">(</span><span style="color: fuchsia;">object_name</span><span style="color: gray;">(</span>D<span style="color: gray;">.</span><span style="color: fuchsia;">object_id</span><span style="color: gray;">,</span> D<span style="color: gray;">.</span>database_id<span style="color: gray;">)),</span> <span style="color: red;">N'-'</span><span style="color: gray;">)</span> <span style="color: blue;">as</span> [Module]<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; QP<span style="color: gray;">.</span>query_plan <span style="color: blue;">as</span> [Query plan]<br /> <span style="color: blue;">from</span> <span style="color: green;">sys</span><span style="color: gray;">.</span><span style="color: green;">dm_exec_procedure_stats</span> <span style="color: blue;">as</span> D<br /> &nbsp;&nbsp;&nbsp;&nbsp; <span style="color: gray;">outer</span> <span style="color: gray;">apply</span> <span style="color: green;">sys</span><span style="color: gray;">.</span><span style="color: green;">dm_exec_query_plan</span><span style="color: gray;">(</span>D<span style="color: gray;">.</span>plan_handle<span style="color: gray;">)</span> <span style="color: blue;">as</span> QP<br /> <span style="color: green;">--where D.database_id = db_id()<br /> </span><span style="color: blue;">order</span> <span style="color: blue;">by</span> [Total logical reads] <span style="color: blue;">desc</span><span style="color: gray;">;</span></p>
<p class="MsoNormal">If a module is performing more logical reads than expected, it may indicate poor logic or missing indexes. Adding the missing indexes will make some updates more expensive but overall it may improve the performance of the application. In SQL Server Management Studio (SSMS), you can click on the result set&rsquo;s query plan column to see the query plan and further investigate the cause of unexpected logical reads.</p>
<p class="MsoNormal">Logical reads, that do not result in physical reads, may cause issues if the pages should not otherwise be in memory. Essentially, the module is causing memory to be wasted that might be better used elsewhere or not even be required.</p>
<h2>Module physical reads</h2>
<p class="MsoNoSpacing">Here is a query to find the modules with the highest physical read volumes.</p>
<p class="Codenospacing"><span style="color: blue;">select</span> <span style="color: blue;">top</span><span style="color: gray;">(</span>10<span style="color: gray;">)</span> D<span style="color: gray;">.</span>total_physical_reads <span style="color: blue;">as</span> [Total physical reads]<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; D<span style="color: gray;">.</span>total_logical_reads <span style="color: blue;">as</span> [Total logical reads]<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; D<span style="color: gray;">.</span>execution_count <span style="color: blue;">as</span> [Executions]<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: fuchsia;">coalesce</span><span style="color: gray;">(</span><span style="color: fuchsia;">quotename</span><span style="color: gray;">(</span><span style="color: fuchsia;">db_name</span><span style="color: gray;">(</span>D<span style="color: gray;">.</span>database_id<span style="color: gray;">)),</span> <span style="color: red;">N'-'</span><span style="color: gray;">)</span> <span style="color: gray;">+</span> <span style="color: red;">N'.'</span> <span style="color: gray;">+</span> <span style="color: fuchsia;">coalesce</span><span style="color: gray;">(</span><span style="color: fuchsia;">quotename</span><span style="color: gray;">(</span><span style="color: fuchsia;">object_schema_name</span><span style="color: gray;">(</span>D<span style="color: gray;">.</span><span style="color: fuchsia;">object_id</span><span style="color: gray;">,</span> D<span style="color: gray;">.</span>database_id<span style="color: gray;">)),</span> <span style="color: red;">N'-'</span><span style="color: gray;">)</span> <span style="color: gray;">+</span> <span style="color: red;">N'.'</span> <span style="color: gray;">+</span> <span style="color: fuchsia;">coalesce</span><span style="color: gray;">(</span><span style="color: fuchsia;">quotename</span><span style="color: gray;">(</span><span style="color: fuchsia;">object_name</span><span style="color: gray;">(</span>D<span style="color: gray;">.</span><span style="color: fuchsia;">object_id</span><span style="color: gray;">,</span> D<span style="color: gray;">.</span>database_id<span style="color: gray;">)),</span> <span style="color: red;">N'-'</span><span style="color: gray;">)</span> <span style="color: blue;">as</span> [Module]<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; QP<span style="color: gray;">.</span>query_plan <span style="color: blue;">as</span> [Query plan]<br /> <span style="color: blue;">from</span> <span style="color: green;">sys</span><span style="color: gray;">.</span><span style="color: green;">dm_exec_procedure_stats</span> <span style="color: blue;">as</span> D<br /> &nbsp;&nbsp;&nbsp;&nbsp; <span style="color: gray;">outer</span> <span style="color: gray;">apply</span> <span style="color: green;">sys</span><span style="color: gray;">.</span><span style="color: green;">dm_exec_query_plan</span><span style="color: gray;">(</span>D<span style="color: gray;">.</span>plan_handle<span style="color: gray;">)</span> <span style="color: blue;">as</span> QP<br /> <span style="color: green;">--where D.database_id = db_id()<br /> </span><span style="color: blue;">order</span> <span style="color: blue;">by</span> [Total physical reads] <span style="color: blue;">desc</span><span style="color: gray;">;</span></p>
<p class="MsoNormal">If a module is performing more physical reads than expected, it may indicate poor logic or missing indexes. Since physical reads take much more time than pure logical reads they are a major cause of latency in database operations.</p>
<h2>Statement logical reads</h2>
<p class="MsoNoSpacing">Often individual T-SQL statements cause high logical and physical read volumes. Here is a query to find statements with the highest logical read volumes.</p>
<p class="Codenospacing"><span style="color: blue;">select</span> <span style="color: blue;">top</span><span style="color: gray;">(</span>10<span style="color: gray;">)</span> <span style="color: fuchsia;">sum</span><span style="color: gray;">(</span>Q<span style="color: gray;">.</span>total_physical_reads<span style="color: gray;">)</span> <span style="color: blue;">as</span> [Physical reads]<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: fuchsia;">sum</span><span style="color: gray;">(</span>Q<span style="color: gray;">.</span>total_logical_reads<span style="color: gray;">)</span> <span style="color: blue;">as</span> [Logical reads]<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: fuchsia;">sum</span><span style="color: gray;">(</span>Q<span style="color: gray;">.</span>execution_count<span style="color: gray;">)</span> <span style="color: blue;">as</span> [Execution count]<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: fuchsia;">min</span><span style="color: gray;">(</span><span style="color: fuchsia;">coalesce</span><span style="color: gray;">(</span><span style="color: fuchsia;">quotename</span><span style="color: gray;">(</span><span style="color: fuchsia;">db_name</span><span style="color: gray;">(</span>Q<span style="color: gray;">.</span><span style="color: blue;">dbid</span><span style="color: gray;">)),</span> <span style="color: red;">N'-'</span><span style="color: gray;">)</span> <span style="color: gray;">+</span> <span style="color: red;">N'.'</span> <span style="color: gray;">+</span> <span style="color: fuchsia;">coalesce</span><span style="color: gray;">(</span><span style="color: fuchsia;">quotename</span><span style="color: gray;">(</span><span style="color: fuchsia;">object_schema_name</span><span style="color: gray;">(</span>Q<span style="color: gray;">.</span>objectid<span style="color: gray;">,</span> Q<span style="color: gray;">.</span><span style="color: blue;">dbid</span><span style="color: gray;">)),</span> <span style="color: red;">N'-'</span><span style="color: gray;">)</span> <span style="color: gray;">+</span> <span style="color: red;">N'.'</span> <span style="color: gray;">+</span> <span style="color: fuchsia;">coalesce</span><span style="color: gray;">(</span><span style="color: fuchsia;">quotename</span><span style="color: gray;">(</span><span style="color: fuchsia;">object_name</span><span style="color: gray;">(</span>Q<span style="color: gray;">.</span>objectid<span style="color: gray;">,</span> Q<span style="color: gray;">.</span><span style="color: blue;">dbid</span><span style="color: gray;">)),</span> <span style="color: red;">N'-'</span><span style="color: gray;">))</span> <span style="color: blue;">as</span> [Module]<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: fuchsia;">min</span><span style="color: gray;">(</span>Q<span style="color: gray;">.</span>statement_text<span style="color: gray;">)</span> <span style="color: blue;">as</span> [Statement]<br /> <span style="color: blue;">from </span><span style="color: gray;">(</span><span style="color: blue;">select</span> QS<span style="color: gray;">.*,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ST<span style="color: gray;">.</span><span style="color: blue;">dbid</span> <span style="color: blue;">as</span> <span style="color: blue;">dbid</span><span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ST<span style="color: gray;">.</span>objectid <span style="color: blue;">as</span> objectid<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: fuchsia;">substring</span><span style="color: gray;">(</span>ST<span style="color: gray;">.</span><span style="color: blue;">text</span><span style="color: gray;">,<br /> </span><span style="color: blue;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: gray;">(</span>QS<span style="color: gray;">.</span>statement_start_offset<span style="color: gray;">/</span>2<span style="color: gray;">)</span> <span style="color: gray;">+</span> 1<span style="color: gray;">,<br /> </span><span style="color: blue;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: gray;">((</span><span style="color: blue;">case</span> statement_end_offset <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">when</span> <span style="color: gray;">-</span>1 <span style="color: blue;">then</span> <span style="color: fuchsia;">datalength</span><span style="color: gray;">(</span>ST<span style="color: gray;">.</span><span style="color: blue;">text</span><span style="color: gray;">)<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">else</span> QS<span style="color: gray;">.</span>statement_end_offset <span style="color: blue;">end</span> <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: gray;">-</span> QS<span style="color: gray;">.</span>statement_start_offset<span style="color: gray;">)/</span>2<span style="color: gray;">)</span> <span style="color: gray;">+</span> 1<span style="color: gray;">)</span> <span style="color: blue;">as</span> statement_text<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">from</span> <span style="color: green;">sys</span><span style="color: gray;">.</span><span style="color: green;">dm_exec_query_stats</span> <span style="color: blue;">as</span> QS<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: gray;">cross</span> <span style="color: gray;">apply</span> <span style="color: green;">sys</span><span style="color: gray;">.</span><span style="color: green;">dm_exec_sql_text</span><span style="color: gray;">(</span>QS<span style="color: gray;">.</span><span style="color: blue;">sql_handle</span><span style="color: gray;">)</span> <span style="color: blue;">as</span> ST<span style="color: gray;">)</span> <span style="color: blue;">as</span> Q<br /> <span style="color: green;">--where Q.dbid = db_id()<br /> </span><span style="color: blue;">group</span> <span style="color: blue;">by</span> Q<span style="color: gray;">.</span>query_hash<br /> <span style="color: blue;">order</span> <span style="color: blue;">by</span> [Logical Reads] <span style="color: blue;">desc</span><span style="color: gray;">;</span></p>
<h2>Statement physical reads</h2>
<p class="MsoNoSpacing">Here is a query to find statements with the highest physical read volumes.</p>
<p class="Codenospacing"><span style="color: blue;">select</span> <span style="color: blue;">top</span><span style="color: gray;">(</span>10<span style="color: gray;">)</span> <span style="color: fuchsia;">sum</span><span style="color: gray;">(</span>Q<span style="color: gray;">.</span>total_physical_reads<span style="color: gray;">)</span> <span style="color: blue;">as</span> [Physical reads]<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: fuchsia;">sum</span><span style="color: gray;">(</span>Q<span style="color: gray;">.</span>total_logical_reads<span style="color: gray;">)</span> <span style="color: blue;">as</span> [Logical reads]<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: fuchsia;">sum</span><span style="color: gray;">(</span>Q<span style="color: gray;">.</span>execution_count<span style="color: gray;">)</span> <span style="color: blue;">as</span> [Execution count]<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: fuchsia;">min</span><span style="color: gray;">(</span><span style="color: fuchsia;">coalesce</span><span style="color: gray;">(</span><span style="color: fuchsia;">quotename</span><span style="color: gray;">(</span><span style="color: fuchsia;">db_name</span><span style="color: gray;">(</span>Q<span style="color: gray;">.</span><span style="color: blue;">dbid</span><span style="color: gray;">)),</span> <span style="color: red;">N'-'</span><span style="color: gray;">)</span> <span style="color: gray;">+</span> <span style="color: red;">N'.'</span> <span style="color: gray;">+</span> <span style="color: fuchsia;">coalesce</span><span style="color: gray;">(</span><span style="color: fuchsia;">quotename</span><span style="color: gray;">(</span><span style="color: fuchsia;">object_schema_name</span><span style="color: gray;">(</span>Q<span style="color: gray;">.</span>objectid<span style="color: gray;">,</span> Q<span style="color: gray;">.</span><span style="color: blue;">dbid</span><span style="color: gray;">)),</span> <span style="color: red;">N'-'</span><span style="color: gray;">)</span> <span style="color: gray;">+</span> <span style="color: red;">N'.'</span> <span style="color: gray;">+</span> <span style="color: fuchsia;">coalesce</span><span style="color: gray;">(</span><span style="color: fuchsia;">quotename</span><span style="color: gray;">(</span><span style="color: fuchsia;">object_name</span><span style="color: gray;">(</span>Q<span style="color: gray;">.</span>objectid<span style="color: gray;">,</span> Q<span style="color: gray;">.</span><span style="color: blue;">dbid</span><span style="color: gray;">)),</span> <span style="color: red;">N'-'</span><span style="color: gray;">))</span> <span style="color: blue;">as</span> [Module]<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: fuchsia;">min</span><span style="color: gray;">(</span>Q<span style="color: gray;">.</span>statement_text<span style="color: gray;">)</span> <span style="color: blue;">as</span> [Statement]<br /> <span style="color: blue;">from </span><span style="color: gray;">(</span><span style="color: blue;">select</span> QS<span style="color: gray;">.*,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ST<span style="color: gray;">.</span><span style="color: blue;">dbid</span> <span style="color: blue;">as</span> <span style="color: blue;">dbid</span><span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ST<span style="color: gray;">.</span>objectid <span style="color: blue;">as</span> objectid<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: fuchsia;">substring</span><span style="color: gray;">(</span>ST<span style="color: gray;">.</span><span style="color: blue;">text</span><span style="color: gray;">,<br /> </span><span style="color: blue;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: gray;">(</span>QS<span style="color: gray;">.</span>statement_start_offset<span style="color: gray;">/</span>2<span style="color: gray;">)</span> <span style="color: gray;">+</span> 1<span style="color: gray;">,<br /> </span><span style="color: blue;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: gray;">((</span><span style="color: blue;">case</span> statement_end_offset <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">when</span> <span style="color: gray;">-</span>1 <span style="color: blue;">then</span> <span style="color: fuchsia;">datalength</span><span style="color: gray;">(</span>ST<span style="color: gray;">.</span><span style="color: blue;">text</span><span style="color: gray;">)<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">else</span> QS<span style="color: gray;">.</span>statement_end_offset <span style="color: blue;">end</span> <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: gray;">-</span> QS<span style="color: gray;">.</span>statement_start_offset<span style="color: gray;">)/</span>2<span style="color: gray;">)</span> <span style="color: gray;">+</span> 1<span style="color: gray;">)</span> <span style="color: blue;">as</span> statement_text<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">from</span> <span style="color: green;">sys</span><span style="color: gray;">.</span><span style="color: green;">dm_exec_query_stats</span> <span style="color: blue;">as</span> QS<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: gray;">cross</span> <span style="color: gray;">apply</span> <span style="color: green;">sys</span><span style="color: gray;">.</span><span style="color: green;">dm_exec_sql_text</span><span style="color: gray;">(</span>QS<span style="color: gray;">.</span><span style="color: blue;">sql_handle</span><span style="color: gray;">)</span> <span style="color: blue;">as</span> ST<span style="color: gray;">)</span> <span style="color: blue;">as</span> Q<br /> <span style="color: green;">--where Q.dbid = db_id()<br /> </span><span style="color: blue;">group</span> <span style="color: blue;">by</span> Q<span style="color: gray;">.</span>query_hash<br /> <span style="color: blue;">order</span> <span style="color: blue;">by</span> [Physical Reads] <span style="color: blue;">desc</span><span style="color: gray;">;</span></p>
<p class="MsoNormal">These two queries can be particularly useful in environments where the application runs queries directly.</p>
<h2>Module writes</h2>
<p class="MsoNoSpacing">Module and statement logical write volumes are often not comparable across modules and statements. This is because of the lazy writer issue mentioned above. Many logical writes that append to an index may have lower actual impact than a few writes to random places in the same index. Thus the results of these queries needs to be interpreted carefully.</p>
<p class="MsoNoSpacing">&nbsp;</p>
<p class="MsoNoSpacing">Here is a query to find the modules with the highest logical write volumes.</p>
<p class="Codenospacing"><span style="color: blue;">select</span> <span style="color: blue;">top</span><span style="color: gray;">(</span>10<span style="color: gray;">)</span> D<span style="color: gray;">.</span>total_logical_writes <span style="color: blue;">as</span> [Total logical writes]<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; D<span style="color: gray;">.</span>execution_count <span style="color: blue;">as</span> [Executions]<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: fuchsia;">coalesce</span><span style="color: gray;">(</span><span style="color: fuchsia;">quotename</span><span style="color: gray;">(</span><span style="color: fuchsia;">db_name</span><span style="color: gray;">(</span>D<span style="color: gray;">.</span>database_id<span style="color: gray;">)),</span> <span style="color: red;">N'-'</span><span style="color: gray;">)</span> <span style="color: gray;">+</span> <span style="color: red;">N'.'</span> <span style="color: gray;">+</span> <span style="color: fuchsia;">coalesce</span><span style="color: gray;">(</span><span style="color: fuchsia;">quotename</span><span style="color: gray;">(</span><span style="color: fuchsia;">object_schema_name</span><span style="color: gray;">(</span>D<span style="color: gray;">.</span><span style="color: fuchsia;">object_id</span><span style="color: gray;">,</span> D<span style="color: gray;">.</span>database_id<span style="color: gray;">)),</span> <span style="color: red;">N'-'</span><span style="color: gray;">)</span> <span style="color: gray;">+</span> <span style="color: red;">N'.'</span> <span style="color: gray;">+</span> <span style="color: fuchsia;">coalesce</span><span style="color: gray;">(</span><span style="color: fuchsia;">quotename</span><span style="color: gray;">(</span><span style="color: fuchsia;">object_name</span><span style="color: gray;">(</span>D<span style="color: gray;">.</span><span style="color: fuchsia;">object_id</span><span style="color: gray;">,</span> D<span style="color: gray;">.</span>database_id<span style="color: gray;">)),</span> <span style="color: red;">N'-'</span><span style="color: gray;">)</span> <span style="color: blue;">as</span> [Module]<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; QP<span style="color: gray;">.</span>query_plan <span style="color: blue;">as</span> [Query plan]<br /> <span style="color: blue;">from</span> <span style="color: green;">sys</span><span style="color: gray;">.</span><span style="color: green;">dm_exec_procedure_stats</span> <span style="color: blue;">as</span> D<br /> &nbsp;&nbsp;&nbsp;&nbsp; <span style="color: gray;">outer</span> <span style="color: gray;">apply</span> <span style="color: green;">sys</span><span style="color: gray;">.</span><span style="color: green;">dm_exec_query_plan</span><span style="color: gray;">(</span>D<span style="color: gray;">.</span>plan_handle<span style="color: gray;">)</span> <span style="color: blue;">as</span> QP<br /> <span style="color: green;">--where D.database_id = db_id()<br /> </span><span style="color: blue;">order</span> <span style="color: blue;">by</span> [Total logical writes] <span style="color: blue;">desc</span><span style="color: gray;">;</span></p>
<h2>Statement writes</h2>
<p class="MsoNoSpacing">Here is a query to find statements with the highest logical write volumes.</p>
<p class="Codenospacing" style="margin-bottom: 10.0pt;"><span style="color: blue;">select</span> <span style="color: blue;">top</span><span style="color: gray;">(</span>10<span style="color: gray;">)</span> <span style="color: fuchsia;">sum</span><span style="color: gray;">(</span>Q<span style="color: gray;">.</span>total_logical_writes<span style="color: gray;">)</span> <span style="color: blue;">as</span> [Logical writes]<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: fuchsia;">sum</span><span style="color: gray;">(</span>Q<span style="color: gray;">.</span>execution_count<span style="color: gray;">)</span> <span style="color: blue;">as</span> [Execution count]<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: fuchsia;">min</span><span style="color: gray;">(</span><span style="color: fuchsia;">coalesce</span><span style="color: gray;">(</span><span style="color: fuchsia;">quotename</span><span style="color: gray;">(</span><span style="color: fuchsia;">db_name</span><span style="color: gray;">(</span>Q<span style="color: gray;">.</span><span style="color: blue;">dbid</span><span style="color: gray;">)),</span> <span style="color: red;">N'-'</span><span style="color: gray;">)</span> <span style="color: gray;">+</span> <span style="color: red;">N'.'</span> <span style="color: gray;">+</span> <span style="color: fuchsia;">coalesce</span><span style="color: gray;">(</span><span style="color: fuchsia;">quotename</span><span style="color: gray;">(</span><span style="color: fuchsia;">object_schema_name</span><span style="color: gray;">(</span>Q<span style="color: gray;">.</span>objectid<span style="color: gray;">,</span> Q<span style="color: gray;">.</span><span style="color: blue;">dbid</span><span style="color: gray;">)),</span> <span style="color: red;">N'-'</span><span style="color: gray;">)</span> <span style="color: gray;">+</span> <span style="color: red;">N'.'</span> <span style="color: gray;">+</span> <span style="color: fuchsia;">coalesce</span><span style="color: gray;">(</span><span style="color: fuchsia;">quotename</span><span style="color: gray;">(</span><span style="color: fuchsia;">object_name</span><span style="color: gray;">(</span>Q<span style="color: gray;">.</span>objectid<span style="color: gray;">,</span> Q<span style="color: gray;">.</span><span style="color: blue;">dbid</span><span style="color: gray;">)),</span> <span style="color: red;">N'-'</span><span style="color: gray;">))</span> <span style="color: blue;">as</span> [Module]<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: fuchsia;">min</span><span style="color: gray;">(</span>Q<span style="color: gray;">.</span>statement_text<span style="color: gray;">)</span> <span style="color: blue;">as</span> [Statement]<br /> <span style="color: blue;">from </span><span style="color: gray;">(</span><span style="color: blue;">select</span> QS<span style="color: gray;">.*,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ST<span style="color: gray;">.</span><span style="color: blue;">dbid</span> <span style="color: blue;">as</span> <span style="color: blue;">dbid</span><span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ST<span style="color: gray;">.</span>objectid <span style="color: blue;">as</span> objectid<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<span style="color: fuchsia;">substring</span><span style="color: gray;">(</span>ST<span style="color: gray;">.</span><span style="color: blue;">text</span><span style="color: gray;">,<br /> </span><span style="color: blue;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: gray;">(</span>QS<span style="color: gray;">.</span>statement_start_offset<span style="color: gray;">/</span>2<span style="color: gray;">)</span> <span style="color: gray;">+</span> 1<span style="color: gray;">,<br /> </span><span style="color: blue;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: gray;">((</span><span style="color: blue;">case</span> statement_end_offset <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">when</span> <span style="color: gray;">-</span>1 <span style="color: blue;">then</span> <span style="color: fuchsia;">datalength</span><span style="color: gray;">(</span>ST<span style="color: gray;">.</span><span style="color: blue;">text</span><span style="color: gray;">)<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">else</span> QS<span style="color: gray;">.</span>statement_end_offset <span style="color: blue;">end</span> <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: gray;">-</span> QS<span style="color: gray;">.</span>statement_start_offset<span style="color: gray;">)/</span>2<span style="color: gray;">)</span> <span style="color: gray;">+</span> 1<span style="color: gray;">)</span> <span style="color: blue;">as</span> statement_text<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">from</span> <span style="color: green;">sys</span><span style="color: gray;">.</span><span style="color: green;">dm_exec_query_stats</span> <span style="color: blue;">as</span> QS<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: gray;">cross</span> <span style="color: gray;">apply</span> <span style="color: green;">sys</span><span style="color: gray;">.</span><span style="color: green;">dm_exec_sql_text</span><span style="color: gray;">(</span>QS<span style="color: gray;">.</span><span style="color: blue;">sql_handle</span><span style="color: gray;">)</span> <span style="color: blue;">as</span> ST<span style="color: gray;">)</span> <span style="color: blue;">as</span> Q<br /> <span style="color: green;">-- where Q.dbid = db_id()<br /> </span><span style="color: blue;">group</span> <span style="color: blue;">by</span> Q<span style="color: gray;">.</span>query_hash<br /> <span style="color: blue;">order</span> <span style="color: blue;">by</span> [Logical Writes] <span style="color: blue;">desc</span><span style="color: gray;">;</span></p>
<h1>Indexes</h1>
<p class="MsoNoSpacing">Often adding indexes can improve the performance of critical queries. Here is a query to find the indexes that are most likely to improve the overall performance of the database application if added.</p>
<p class="Codenospacing"><span style="color: blue;">select</span> <span style="color: fuchsia;">coalesce</span><span style="color: gray;">(</span><span style="color: fuchsia;">quotename</span><span style="color: gray;">(</span><span style="color: fuchsia;">db_name</span><span style="color: gray;">(</span>MID<span style="color: gray;">.</span>database_id<span style="color: gray;">)),</span> <span style="color: red;">N'-'</span><span style="color: gray;">)</span> <span style="color: gray;">+</span> <span style="color: red;">N'.'</span> <span style="color: gray;">+</span> <span style="color: fuchsia;">coalesce</span><span style="color: gray;">(</span><span style="color: fuchsia;">quotename</span><span style="color: gray;">(</span><span style="color: fuchsia;">object_schema_name</span><span style="color: gray;">(</span>MID<span style="color: gray;">.</span><span style="color: fuchsia;">object_id</span><span style="color: gray;">,</span> MID<span style="color: gray;">.</span>database_id<span style="color: gray;">)),</span> <span style="color: red;">N'-'</span><span style="color: gray;">)</span> <span style="color: gray;">+</span> <span style="color: red;">N'.'</span> <span style="color: gray;">+</span> <span style="color: fuchsia;">coalesce</span><span style="color: gray;">(</span><span style="color: fuchsia;">quotename</span><span style="color: gray;">(</span><span style="color: fuchsia;">object_name</span><span style="color: gray;">(</span>MID<span style="color: gray;">.</span><span style="color: fuchsia;">object_id</span><span style="color: gray;">,</span> MID<span style="color: gray;">.</span>database_id<span style="color: gray;">)),</span> <span style="color: red;">N'-'</span><span style="color: gray;">)</span> <span style="color: blue;">as</span> [Object]<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: fuchsia;">round</span><span style="color: gray;">(</span>MIGS<span style="color: gray;">.</span>avg_total_user_cost <span style="color: gray;">*</span><span style="color: gray;">(</span>MIGS<span style="color: gray;">.</span>avg_user_impact<span style="color: gray;">/</span>100.0<span style="color: gray;">)</span> <span style="color: gray;">*</span><span style="color: gray;">(</span>MIGS<span style="color: gray;">.</span>user_seeks <span style="color: gray;">+</span> MIGS<span style="color: gray;">.</span>user_scans<span style="color: gray;">),</span> 0<span style="color: gray;">)</span> <span style="color: blue;">as</span> [Relative cost]<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: fuchsia;">round</span><span style="color: gray;">(</span>MIGS<span style="color: gray;">.</span>avg_total_user_cost<span style="color: gray;">,</span> 2<span style="color: gray;">)</span> [Average cost]<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: fuchsia;">round</span><span style="color: gray;">(</span>MIGS<span style="color: gray;">.</span>avg_user_impact<span style="color: gray;">,</span> 2<span style="color: gray;">)</span> [Percentage improvement]<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MIGS<span style="color: gray;">.</span>user_scans <span style="color: blue;">as</span> [User scans]<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MIGS<span style="color: gray;">.</span>user_seeks <span style="color: blue;">as</span> [User seeks]<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: fuchsia;">coalesce</span><span style="color: gray;">(</span>MID<span style="color: gray;">.</span>equality_columns<span style="color: gray;">,</span> <span style="color: red;">N''</span><span style="color: gray;">)</span> <span style="color: blue;">as</span> [Equi-join]<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: fuchsia;">coalesce</span><span style="color: gray;">(</span>MID<span style="color: gray;">.</span>inequality_columns<span style="color: gray;">,</span> <span style="color: red;">N''</span><span style="color: gray;">)</span> <span style="color: blue;">as</span> [Inequi-join]<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: fuchsia;">coalesce</span><span style="color: gray;">(</span>MID<span style="color: gray;">.</span>included_columns<span style="color: gray;">,</span> <span style="color: red;">N''</span><span style="color: gray;">)</span> <span style="color: blue;">as</span> [Included]<br /> <span style="color: blue;">from</span> <span style="color: green;">sys</span><span style="color: gray;">.</span><span style="color: green;">dm_db_missing_index_group_stats</span> <span style="color: blue;">as</span> MIGS<br /> &nbsp;&nbsp;&nbsp;&nbsp; <span style="color: gray;">inner</span> <span style="color: gray;">join</span> <span style="color: green;">sys</span><span style="color: gray;">.</span><span style="color: green;">dm_db_missing_index_groups</span> <span style="color: blue;">as</span> MIG <span style="color: blue;">on</span> MIG<span style="color: gray;">.</span>index_group_handle <span style="color: gray;">=</span> MIGS<span style="color: gray;">.</span>group_handle<br /> &nbsp;&nbsp;&nbsp;&nbsp; <span style="color: gray;">inner</span> <span style="color: gray;">join</span> <span style="color: green;">sys</span><span style="color: gray;">.</span><span style="color: green;">dm_db_missing_index_details</span> <span style="color: blue;">as</span> MID <span style="color: blue;">on</span> MID<span style="color: gray;">.</span>index_handle <span style="color: gray;">=</span> MIG<span style="color: gray;">.</span>index_handle<br /> <span style="color: green;">--where MID.database_id = db_id()<br /> </span><span style="color: blue;">order</span> <span style="color: blue;">by</span> [Percentage Improvement] <span style="color: blue;">desc</span><span style="color: gray;">;</span></p>
<p class="MsoNormal">Indexes should be added judiciously since they will slow down some parts of the database application (e.g. updates to the columns in the index) and increase the storage size of the database.</p>
<p class="MsoNoSpacing">Sometimes database applications contain indexes that are rarely used. These indexes slow down updates and increase storage and related costs (e.g. backup). Here is a query to find the usage of all indexes in a database.</p>
<p class="Codenospacing"><span style="color: blue;">select</span> <span style="color: fuchsia;">coalesce</span><span style="color: gray;">(</span><span style="color: fuchsia;">quotename</span><span style="color: gray;">(</span><span style="color: fuchsia;">db_name</span><span style="color: gray;">(</span>US<span style="color: gray;">.</span>database_id<span style="color: gray;">)),</span> <span style="color: red;">N'-'</span><span style="color: gray;">)</span> <span style="color: gray;">+</span> <span style="color: red;">N'.'</span> <span style="color: gray;">+</span> <span style="color: fuchsia;">coalesce</span><span style="color: gray;">(</span><span style="color: fuchsia;">quotename</span><span style="color: gray;">(</span><span style="color: fuchsia;">object_schema_name</span><span style="color: gray;">(</span>US<span style="color: gray;">.</span><span style="color: fuchsia;">object_id</span><span style="color: gray;">,</span> US<span style="color: gray;">.</span>database_id<span style="color: gray;">)),</span> <span style="color: red;">N'-'</span><span style="color: gray;">)</span> <span style="color: gray;">+</span> <span style="color: red;">N'.'</span> <span style="color: gray;">+</span> <span style="color: fuchsia;">coalesce</span><span style="color: gray;">(</span><span style="color: fuchsia;">quotename</span><span style="color: gray;">(</span><span style="color: fuchsia;">object_name</span><span style="color: gray;">(</span>US<span style="color: gray;">.</span><span style="color: fuchsia;">object_id</span><span style="color: gray;">,</span> US<span style="color: gray;">.</span>database_id<span style="color: gray;">)),</span> <span style="color: red;">N'-'</span><span style="color: gray;">)</span> <span style="color: blue;">as</span> [Object]<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; I<span style="color: gray;">.</span>name <span style="color: blue;">as</span> [Index]<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: fuchsia;">convert</span><span style="color: gray;">(</span><span style="color: blue;">decimal</span><span style="color: gray;">(</span>38<span style="color: gray;">,</span>2<span style="color: gray;">),</span> PS<span style="color: gray;">.</span>[Page count]<span style="color: gray;">/</span>128.0<span style="color: gray;">)</span> <span style="color: blue;">as</span> [Size (MB)]<span style="color: gray;">,<br /> </span><span style="color: blue;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: gray;">(</span>US<span style="color: gray;">.</span>user_seeks <span style="color: gray;">+</span> US<span style="color: gray;">.</span>user_scans <span style="color: gray;">+</span> US<span style="color: gray;">.</span>user_lookups<span style="color: gray;">)</span> <span style="color: blue;">as</span> [User operations]<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; US<span style="color: gray;">.</span>user_seeks <span style="color: blue;">as</span> [User seeks]<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; US<span style="color: gray;">.</span>user_scans <span style="color: blue;">as</span> [User scans]<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; US<span style="color: gray;">.</span>user_lookups <span style="color: blue;">as</span> [User bookmark lookups]<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; US<span style="color: gray;">.</span>user_updates <span style="color: blue;">as</span> [User updates]<br /> <span style="color: blue;">from</span> <span style="color: green;">sys</span><span style="color: gray;">.</span><span style="color: green;">dm_db_index_usage_stats</span> <span style="color: blue;">as</span> US<br /> &nbsp;&nbsp;&nbsp;&nbsp; <span style="color: gray;">cross</span> <span style="color: gray;">apply</span><span style="color: gray;">(</span><span style="color: blue;">select</span> IPS<span style="color: gray;">.</span><span style="color: fuchsia;">object_id</span><span style="color: gray;">,</span> IPS<span style="color: gray;">.</span>index_id<span style="color: gray;">,</span> <span style="color: fuchsia;">sum</span><span style="color: gray;">(</span>IPS<span style="color: gray;">.</span>page_count<span style="color: gray;">)<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">from</span> <span style="color: green;">sys</span><span style="color: gray;">.</span><span style="color: green;">dm_db_index_physical_stats</span><span style="color: gray;">(</span>US<span style="color: gray;">.</span>database_id<span style="color: gray;">,</span> US<span style="color: gray;">.</span><span style="color: fuchsia;">object_id</span><span style="color: gray;">,</span> US<span style="color: gray;">.</span>index_id<span style="color: gray;">,</span> <span style="color: gray;">null,</span> <span style="color: red;">N'SAMPLED'</span> <span style="color: green;">/* For non-leaf pages use N'DETAILED'*/</span><span style="color: gray;">)</span> <span style="color: blue;">as</span> IPS<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">group</span> <span style="color: blue;">by</span> IPS<span style="color: gray;">.</span><span style="color: fuchsia;">object_id</span><span style="color: gray;">,</span> IPS<span style="color: gray;">.</span>index_id<span style="color: gray;">)</span> <span style="color: blue;">as</span> PS<span style="color: gray;">(</span>[Object]<span style="color: gray;">,</span> [Index]<span style="color: gray;">,</span> [Page count]<span style="color: gray;">)<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: gray;">inner</span> <span style="color: gray;">join</span> <span style="color: green;">sys</span><span style="color: gray;">.</span><span style="color: green;">indexes</span> <span style="color: blue;">as</span> I <span style="color: blue;">on</span> I<span style="color: gray;">.</span><span style="color: fuchsia;">object_id</span> <span style="color: gray;">=</span> US<span style="color: gray;">.</span><span style="color: fuchsia;">object_id</span> <span style="color: gray;">and<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; I<span style="color: gray;">.</span>index_id <span style="color: gray;">=</span> US<span style="color: gray;">.</span>index_id<br /> <span style="font-size: 10.0pt; font-family: 'Courier New'; color: blue;">where</span><span style="font-size: 10.0pt; font-family: 'Courier New';"> D<span style="color: gray;">.</span>database_id <span style="color: gray;">=</span> <span style="color: fuchsia;">db_id</span><span style="color: gray;">()</span></span><span style="color: green;"><br /> </span><span style="color: blue;">order</span> <span style="color: blue;">by</span> [User Operations]<span style="color: gray;">,</span> [Object]<span style="color: gray;">,</span> [Index]<span style="color: gray;">;</span></p>
<p class="MsoNormal">Indexes with low use are candidates for removal.</p>
<p class="MsoNoSpacing">Indexes may become fragmented in these ways:</p>
<p class="MsoListNumberCxSpFirst">1.<span style="font: 7.0pt 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>The pages may become logically out-of-order on disk. This was once undesirable because logical order was closely related to physical order, sequential disk access was faster than non-sequential access and indexes are frequently scanned in page order. However, this is rarely an issue now because RAID, SANs, Windows Server storage and many disk drives and controllers reorder pages on disk so the logical order does not reflect the physical order and thus pages being in logical order does not give any performance gain. Also, for some technologies like SSDs sequential physical access may give no gain in performance.</p>
<p class="MsoListNumberCxSpLast" style="margin-bottom: .0001pt;">2.<span style="font: 7.0pt 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>Secondly, the pages may be non-full. Often, many pages in an index must be read to complete a SQL Server operation and non-full pages have less data per page than full pages thus non-full pages will often mean more pages need to be read from disk and memory buffers are less efficient. However, when data is inserted into a full page it will split into two half full pages which are less efficient. Thus in general, the best performance is usually gained by a target of pages that are almost full but with enough room for inserts to rarely split a page.</p>
<p class="MsoNoSpacing">There are numerous considerations in determining if index fragmentation is likely to cause performance issues. For example, SQL Server fetches entire <em>extents</em> (a group of 8 pages of 8Kb each) not pages thus fragmentation in indexes of just a few extents is unlikely to have a performance impact. These considerations lead to the following heuristic based query for determining which indexes need defragmentation in a database.</p>
<p class="Codenospacing"><span style="color: blue;">select</span> coalesce<span style="color: gray;">(</span>quotename<span style="color: gray;">(</span><span style="color: teal;">D</span><span style="color: gray;">.</span><span style="color: teal;">name</span><span style="color: gray;">),</span> <span style="color: red;">N'-'</span><span style="color: gray;">)</span> <span style="color: gray;">+</span> <span style="color: red;">N'.'</span> <span style="color: gray;">+</span> coalesce<span style="color: gray;">(</span>quotename<span style="color: gray;">(</span>object_schema_name<span style="color: gray;">(</span><span style="color: teal;">IPS</span><span style="color: gray;">.</span>object_id<span style="color: gray;">,</span> <span style="color: teal;">D</span><span style="color: gray;">.</span><span style="color: teal;">database_id</span><span style="color: gray;">)),</span> <span style="color: red;">N'-'</span><span style="color: gray;">)</span> <span style="color: gray;">+</span> <span style="color: red;">N'.'</span> <span style="color: gray;">+</span> coalesce<span style="color: gray;">(</span>quotename<span style="color: gray;">(</span>object_name<span style="color: gray;">(</span><span style="color: teal;">IPS</span><span style="color: gray;">.</span>object_id<span style="color: gray;">,</span> <span style="color: teal;">D</span><span style="color: gray;">.</span><span style="color: teal;">database_id</span><span style="color: gray;">)),</span> <span style="color: red;">N'-'</span><span style="color: gray;">)</span> <span style="color: blue;">as</span> <span style="color: teal;">[Object]</span><span style="color: gray;">,</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: teal;">I</span><span style="color: gray;">.</span><span style="color: teal;">name</span> <span style="color: blue;">as</span> <span style="color: teal;">[Index]</span><span style="color: gray;">,</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: teal;">IPS</span><span style="color: gray;">.</span><span style="color: teal;">partition_number</span> <span style="color: blue;">as</span> <span style="color: teal;">[Partition]</span><span style="color: gray;">,</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: teal;">IPS</span><span style="color: gray;">.</span><span style="color: teal;">index_level</span> <span style="color: blue;">as</span> <span style="color: teal;">[Level]</span><span style="color: gray;">,</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; convert<span style="color: gray;">(</span><span style="color: blue;">decimal</span><span style="color: gray;">(</span>38<span style="color: gray;">,</span>2<span style="color: gray;">),</span> <span style="color: teal;">IPS</span><span style="color: gray;">.</span><span style="color: teal;">page_count</span><span style="color: gray;">/</span>128.0<span style="color: gray;">)</span> <span style="color: blue;">as</span> <span style="color: teal;">[Size (MB)]</span><span style="color: gray;">,</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: teal;">IPS</span><span style="color: gray;">.</span><span style="color: teal;">avg_fragmentation_in_percent</span> <span style="color: blue;">as</span> <span style="color: teal;">[Mean fragementation (%)]</span><span style="color: gray;">,</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: teal;">IPS</span><span style="color: gray;">.</span><span style="color: teal;">avg_page_space_used_in_percent</span> <span style="color: blue;">as</span> <span style="color: teal;">[Mean&nbsp; space Used (%)]</span><span style="color: gray;">,</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">case</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">when</span> <span style="color: teal;">IPS</span><span style="color: gray;">.</span><span style="color: teal;">avg_fragmentation_in_percent</span> <span style="color: gray;">&lt;</span> 30.0 <span style="color: blue;">then</span> <span style="color: red;">N'Reorganize'</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">else</span> <span style="color: red;">N'Rebuild'</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">end</span> <span style="color: blue;">as</span> <span style="color: teal;">[Action]</span><br /> <span style="color: blue;">from</span> <span style="color: green;">sys</span><span style="color: gray;">.</span><span style="color: green;">databases</span> <span style="color: blue;">as</span> <span style="color: teal;">D</span><br /> &nbsp;&nbsp;&nbsp;&nbsp; <span style="color: gray;">cross</span> <span style="color: gray;">apply</span> <span style="color: green;">sys</span><span style="color: gray;">.</span><span style="color: green;">dm_db_index_physical_stats</span><span style="color: gray;">(</span><span style="color: teal;">D</span><span style="color: gray;">.</span><span style="color: teal;">database_id</span><span style="color: gray;">,</span> <span style="color: gray;">null,</span> <span style="color: gray;">null,</span> <span style="color: gray;">null,</span> <span style="color: red;">N'SAMPLED'</span> <span style="color: green;">/* For non-leaf pages use N'DETAILED'*/</span><span style="color: gray;">)</span> <span style="color: blue;">as</span> <span style="color: teal;">IPS</span><br /> &nbsp;&nbsp;&nbsp;&nbsp; <span style="color: gray;">inner</span> <span style="color: gray;">join</span> <span style="color: green;">sys</span><span style="color: gray;">.</span><span style="color: green;">indexes</span> <span style="color: blue;">as</span> <span style="color: teal;">I</span> <span style="color: blue;">on</span> <span style="color: teal;">I</span><span style="color: gray;">.</span>object_id <span style="color: gray;">=</span> <span style="color: teal;">IPS</span><span style="color: gray;">.</span>object_id <span style="color: gray;">and</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: teal;">I</span><span style="color: gray;">.</span><span style="color: teal;">index_id</span> <span style="color: gray;">=</span> <span style="color: teal;">IPS</span><span style="color: gray;">.</span><span style="color: teal;">index_id</span><br /> <span style="font-size: 10.0pt; font-family: 'Courier New'; color: blue;">where</span><span style="font-size: 10.0pt; font-family: 'Courier New';"> D<span style="color: gray;">.</span>database_id <span style="color: gray;">=</span> <span style="color: fuchsia;">db_id</span><span style="color: gray;">()</span> <span style="color: gray;">and</span></span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: teal;">IPS</span><span style="color: gray;">.</span><span style="color: teal;">alloc_unit_type_desc</span> <span style="color: gray;">=</span> <span style="color: red;">'IN_ROW_DATA'</span> <span style="color: gray;">and</span><br /> <span style="color: blue;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: gray;">((</span><span style="color: teal;">IPS</span><span style="color: gray;">.</span><span style="color: teal;">page_count</span> <span style="color: gray;">&gt;</span> 24 <span style="color: gray;">and</span> <span style="color: teal;">IPS</span><span style="color: gray;">.</span><span style="color: teal;">avg_fragmentation_in_percent</span> <span style="color: gray;">&gt;</span> 5.0<span style="color: gray;">)</span> <span style="color: gray;">or</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: green;">-- Fragmented (only relevant where in-order pages are faster to read or write).</span><br /> <span style="color: blue;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: gray;">(</span><span style="color: teal;">IPS</span><span style="color: gray;">.</span><span style="color: teal;">page_count</span> <span style="color: gray;">&gt;</span> 8 <span style="color: gray;">and</span> <span style="color: teal;">IPS</span><span style="color: gray;">.</span><span style="color: teal;">avg_page_space_used_in_percent</span> <span style="color: gray;">&lt;</span> <span style="color: teal;">I</span><span style="color: gray;">.</span><span style="color: teal;">fill_factor</span><span style="color: gray;">*</span>0.9<span style="color: gray;">))</span> <span style="color: green;">-- Compaction needed.</span><br /> <span style="color: blue;">order</span> <span style="color: blue;">by</span> <span style="color: teal;">[Object]</span><span style="color: gray;">,</span> <span style="color: teal;">[Index]</span><span style="color: gray;">,</span> <span style="color: teal;">[Partition]</span><span style="color: gray;">,</span> <span style="color: teal;">[Level]</span><span style="color: gray;">;</span></p>
<p class="MsoNoSpacing">Sometimes, it is more efficient to reorganize an index than to rebuild it. The above query also heuristically determines if the index should be reorganized or rebuilt. Here is a query that does not use any heuristics to filter the results:</p>
<p class="Codenospacing"><span style="color: blue;">select</span> coalesce<span style="color: gray;">(</span>quotename<span style="color: gray;">(</span><span style="color: teal;">D</span><span style="color: gray;">.</span><span style="color: teal;">name</span><span style="color: gray;">),</span> <span style="color: red;">N'-'</span><span style="color: gray;">)</span> <span style="color: gray;">+</span> <span style="color: red;">N'.'</span> <span style="color: gray;">+</span> coalesce<span style="color: gray;">(</span>quotename<span style="color: gray;">(</span>object_schema_name<span style="color: gray;">(</span><span style="color: teal;">IPS</span><span style="color: gray;">.</span>object_id<span style="color: gray;">,</span> <span style="color: teal;">D</span><span style="color: gray;">.</span><span style="color: teal;">database_id</span><span style="color: gray;">)),</span> <span style="color: red;">N'-'</span><span style="color: gray;">)</span> <span style="color: gray;">+</span> <span style="color: red;">N'.'</span> <span style="color: gray;">+</span> coalesce<span style="color: gray;">(</span>quotename<span style="color: gray;">(</span>object_name<span style="color: gray;">(</span><span style="color: teal;">IPS</span><span style="color: gray;">.</span>object_id<span style="color: gray;">,</span> <span style="color: teal;">D</span><span style="color: gray;">.</span><span style="color: teal;">database_id</span><span style="color: gray;">)),</span> <span style="color: red;">N'-'</span><span style="color: gray;">)</span> <span style="color: blue;">as</span> <span style="color: teal;">[Object]</span><span style="color: gray;">,</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: teal;">I</span><span style="color: gray;">.</span><span style="color: teal;">name</span> <span style="color: blue;">as</span> <span style="color: teal;">[Index]</span><span style="color: gray;">,</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: teal;">IPS</span><span style="color: gray;">.</span><span style="color: teal;">partition_number</span> <span style="color: blue;">as</span> <span style="color: teal;">[Partition]</span><span style="color: gray;">,</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: teal;">IPS</span><span style="color: gray;">.</span><span style="color: teal;">index_level</span> <span style="color: blue;">as</span> <span style="color: teal;">[Level]</span><span style="color: gray;">,</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; convert<span style="color: gray;">(</span><span style="color: blue;">decimal</span><span style="color: gray;">(</span>38<span style="color: gray;">,</span>2<span style="color: gray;">),</span> <span style="color: teal;">IPS</span><span style="color: gray;">.</span><span style="color: teal;">page_count</span><span style="color: gray;">/</span>128.0<span style="color: gray;">)</span> <span style="color: blue;">as</span> <span style="color: teal;">[Size (MB)]</span><span style="color: gray;">,</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: teal;">IPS</span><span style="color: gray;">.</span><span style="color: teal;">avg_fragmentation_in_percent</span> <span style="color: blue;">as</span> <span style="color: teal;">[Mean fragementation (%)]</span><span style="color: gray;">,</span> <span style="color: green;">-- Only relevant where in-order pages are faster to read or write.</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: teal;">IPS</span><span style="color: gray;">.</span><span style="color: teal;">avg_page_space_used_in_percent</span> <span style="color: blue;">as</span> <span style="color: teal;">[Mean&nbsp; space Used (%)]</span><br /> <span style="color: blue;">from</span> <span style="color: green;">sys</span><span style="color: gray;">.</span><span style="color: green;">databases</span> <span style="color: blue;">as</span> <span style="color: teal;">D</span><br /> &nbsp;&nbsp;&nbsp;&nbsp; <span style="color: gray;">cross</span> <span style="color: gray;">apply</span> <span style="color: green;">sys</span><span style="color: gray;">.</span><span style="color: green;">dm_db_index_physical_stats</span><span style="color: gray;">(</span><span style="color: teal;">D</span><span style="color: gray;">.</span><span style="color: teal;">database_id</span><span style="color: gray;">,</span> <span style="color: gray;">null,</span> <span style="color: gray;">null,</span> <span style="color: gray;">null,</span> <span style="color: red;">N'SAMPLED'</span> <span style="color: green;">/* For non-leaf pages use N'DETAILED'*/</span><span style="color: gray;">)</span> <span style="color: blue;">as</span> <span style="color: teal;">IPS</span><br /> &nbsp;&nbsp;&nbsp;&nbsp; <span style="color: gray;">inner</span> <span style="color: gray;">join</span> <span style="color: green;">sys</span><span style="color: gray;">.</span><span style="color: green;">indexes</span> <span style="color: blue;">as</span> <span style="color: teal;">I</span> <span style="color: blue;">on</span> <span style="color: teal;">I</span><span style="color: gray;">.</span>object_id <span style="color: gray;">=</span> <span style="color: teal;">IPS</span><span style="color: gray;">.</span>object_id <span style="color: gray;">and</span> <span style="color: teal;">I</span><span style="color: gray;">.</span><span style="color: teal;">index_id</span> <span style="color: gray;">=</span> <span style="color: teal;">IPS</span><span style="color: gray;">.</span><span style="color: teal;">index_id</span><br /> <span style="font-size: 10.0pt; font-family: 'Courier New'; color: blue;">where</span><span style="font-size: 10.0pt; font-family: 'Courier New';"> D<span style="color: gray;">.</span>database_id <span style="color: gray;">=</span> <span style="color: fuchsia;">db_id</span><span style="color: gray;">()</span></span><br /> <span style="color: blue;">order</span> <span style="color: blue;">by</span> <span style="color: teal;">[Object]</span><span style="color: gray;">,</span> <span style="color: teal;">[Index]</span><span style="color: gray;">,</span> <span style="color: teal;">[Partition]</span><span style="color: gray;">,</span> <span style="color: teal;">[Level]</span><span style="color: gray;">;</span></p>
<p class="MsoNormal">For efficiency reasons, both queries sample leaf pages in the B+-trees. Using the <em>DETAILED</em> option instead will give data for all pages.</p>
<h1>Storage</h1>
<p class="MsoNormal">Storage is usually cheap compared to the engineering cost of reducing it. However, for databases that consume a large amount of storage it may be worth the engineering investment to reduce storage costs. In a storage cost analysis there are usually two values of interest: the number of rows and the mean size of each row. If the number of rows is unexpectedly large there may an error in the application. Often when troubleshooting database size growth this value indicates where the issue is. If the mean row size is unexpectedly large it may indicate over indexing of large values.</p>
<p class="MsoNoSpacing">Here is a query to find the approximate storage used by database objects</p>
<p class="Codenospacing"><span style="color: blue;">select</span> <span style="color: blue;">top</span><span style="color: gray;">(</span>10<span style="color: gray;">)</span> db_name<span style="color: gray;">()</span> <span style="color: gray;">+</span> <span style="color: red;">N'.'</span> <span style="color: gray;">+</span> coalesce<span style="color: gray;">(</span>quotename<span style="color: gray;">(</span>object_schema_name<span style="color: gray;">(</span><span style="color: teal;">PS</span><span style="color: gray;">.</span>object_id<span style="color: gray;">)),</span> <span style="color: red;">N'-'</span><span style="color: gray;">)</span> <span style="color: gray;">+</span> <span style="color: red;">N'.'</span> <span style="color: gray;">+</span> coalesce<span style="color: gray;">(</span>quotename<span style="color: gray;">(</span>object_name<span style="color: gray;">(</span><span style="color: teal;">PS</span><span style="color: gray;">.</span>object_id<span style="color: gray;">)),</span> <span style="color: red;">N'-'</span><span style="color: gray;">)</span> <span style="color: blue;">as</span> <span style="color: teal;">[Object]</span><span style="color: gray;">,</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;convert<span style="color: gray;">(</span><span style="color: blue;">decimal</span><span style="color: gray;">(</span>38<span style="color: gray;">,</span>2<span style="color: gray;">),</span> sum<span style="color: gray;">(</span><span style="color: teal;">PS</span><span style="color: gray;">.</span><span style="color: teal;">used_page_count</span><span style="color: gray;">)/</span>128.0<span style="color: gray;">)</span> <span style="color: blue;">as</span> <span style="color: teal;">[Size (MB)]</span><span style="color: gray;">,</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sum<span style="color: gray;">(</span><span style="color: blue;">case</span> <span style="color: blue;">when</span> <span style="color: teal;">PS</span><span style="color: gray;">.</span><span style="color: teal;">index_id</span> <span style="color: gray;">in</span><span style="color: gray;">(</span>0<span style="color: gray;">,</span> 1<span style="color: gray;">)</span> <span style="color: blue;">then</span> <span style="color: teal;">PS</span><span style="color: gray;">.</span><span style="color: teal;">row_count</span> <span style="color: blue;">else</span> 0 <span style="color: blue;">end</span><span style="color: gray;">)</span> <span style="color: blue;">as</span> <span style="color: teal;">[Rows]</span><span style="color: gray;">,</span><br /> <span style="color: blue;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: gray;">(</span>sum<span style="color: gray;">(</span><span style="color: teal;">PS</span><span style="color: gray;">.</span><span style="color: teal;">used_page_count</span><span style="color: gray;">)*</span>8000<span style="color: gray;">)/</span>sum<span style="color: gray;">(</span><span style="color: blue;">case</span> <span style="color: blue;">when</span> <span style="color: teal;">PS</span><span style="color: gray;">.</span><span style="color: teal;">index_id</span> <span style="color: gray;">in</span><span style="color: gray;">(</span>0<span style="color: gray;">,</span> 1<span style="color: gray;">)</span> <span style="color: blue;">then</span> <span style="color: teal;">PS</span><span style="color: gray;">.</span><span style="color: teal;">row_count</span> <span style="color: blue;">else</span> 0 <span style="color: blue;">end</span><span style="color: gray;">)</span> <span style="color: blue;">as</span> <span style="color: teal;">[Mean row size (Bytes)]</span><br /> <br /> <span style="color: blue;">from</span> <span style="color: green;">sys</span><span style="color: gray;">.</span><span style="color: green;">dm_db_partition_stats</span> <span style="color: blue;">as</span> <span style="color: teal;">PS</span><br /> <span style="color: blue;">group</span> <span style="color: blue;">by</span> db_name<span style="color: gray;">()</span> <span style="color: gray;">+</span> <span style="color: red;">N'.'</span> <span style="color: gray;">+</span> coalesce<span style="color: gray;">(</span>quotename<span style="color: gray;">(</span>object_schema_name<span style="color: gray;">(</span><span style="color: teal;">PS</span><span style="color: gray;">.</span>object_id<span style="color: gray;">)),</span> <span style="color: red;">N'-'</span><span style="color: gray;">)</span> <span style="color: gray;">+</span> <span style="color: red;">N'.'</span> <span style="color: gray;">+</span> coalesce<span style="color: gray;">(</span>quotename<span style="color: gray;">(</span>object_name<span style="color: gray;">(</span><span style="color: teal;">PS</span><span style="color: gray;">.</span>object_id<span style="color: gray;">)),</span> <span style="color: red;">N'-'</span><span style="color: gray;">)</span><br /> <span style="color: blue;">order</span> <span style="color: blue;">by</span> <span style="color: teal;">[Size (MB)]</span> <span style="color: blue;">desc</span></p>
<p class="MsoNoSpacing">The query runs quickly but is based on cached information that may be out-of-date. Here is a query to find the exact storage used by database objects:</p>
<p class="Codenospacing"><span style="color: blue;">select</span> <span style="color: blue;">top </span><span style="color: gray;">(</span>10<span style="color: gray;">)</span> coalesce<span style="color: gray;">(</span>quotename<span style="color: gray;">(</span>db_name<span style="color: gray;">(</span><span style="color: teal;">D</span><span style="color: gray;">.</span><span style="color: teal;">database_id</span><span style="color: gray;">)),</span> <span style="color: red;">N'-'</span><span style="color: gray;">)</span> <span style="color: gray;">+</span> <span style="color: red;">N'.'</span> <span style="color: gray;">+</span> coalesce<span style="color: gray;">(</span>quotename<span style="color: gray;">(</span>object_schema_name<span style="color: gray;">(</span><span style="color: teal;">PS</span><span style="color: gray;">.</span>object_id<span style="color: gray;">,</span> <span style="color: teal;">D</span><span style="color: gray;">.</span><span style="color: teal;">database_id</span><span style="color: gray;">)),</span> <span style="color: red;">N'-'</span><span style="color: gray;">)</span> <span style="color: gray;">+</span> <span style="color: red;">N'.'</span> <span style="color: gray;">+</span> coalesce<span style="color: gray;">(</span>quotename<span style="color: gray;">(</span>object_name<span style="color: gray;">(</span><span style="color: teal;">PS</span><span style="color: gray;">.</span>object_id<span style="color: gray;">,</span> <span style="color: teal;">D</span><span style="color: gray;">.</span><span style="color: teal;">database_id</span><span style="color: gray;">)),</span> <span style="color: red;">N'-'</span><span style="color: gray;">)</span> <span style="color: blue;">as</span> <span style="color: teal;">[Object]</span><span style="color: gray;">,</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; convert<span style="color: gray;">(</span><span style="color: blue;">decimal</span><span style="color: gray;">(</span>38<span style="color: gray;">,</span>2<span style="color: gray;">),</span> sum<span style="color: gray;">(</span><span style="color: teal;">PS</span><span style="color: gray;">.</span><span style="color: teal;">page_count</span><span style="color: gray;">)/</span>128.0<span style="color: gray;">)</span> <span style="color: blue;">as</span> <span style="color: teal;">[Size (MB)]</span><br /> <span style="color: blue;">from</span> <span style="color: green;">sys</span><span style="color: gray;">.</span><span style="color: green;">databases</span> <span style="color: blue;">as</span> <span style="color: teal;">D</span><br /> &nbsp;&nbsp;&nbsp;&nbsp; <span style="color: gray;">cross</span> <span style="color: gray;">apply</span> <span style="color: green;">sys</span><span style="color: gray;">.</span><span style="color: green;">dm_db_index_physical_stats</span><span style="color: gray;">(</span><span style="color: teal;">D</span><span style="color: gray;">.</span><span style="color: teal;">database_id</span><span style="color: gray;">,</span> <span style="color: gray;">null,</span> <span style="color: gray;">null,</span> <span style="color: gray;">null,</span> <span style="color: red;">N'DETAILED'</span><span style="color: gray;">)</span> <span style="color: blue;">as</span> <span style="color: teal;">PS</span><br /> <span style="color: green;">--where D.database_id = db_id()</span><br /> <span style="color: blue;">group</span> <span style="color: blue;">by</span> coalesce<span style="color: gray;">(</span>quotename<span style="color: gray;">(</span>db_name<span style="color: gray;">(</span><span style="color: teal;">D</span><span style="color: gray;">.</span><span style="color: teal;">database_id</span><span style="color: gray;">)),</span> <span style="color: red;">N'-'</span><span style="color: gray;">)</span> <span style="color: gray;">+</span> <span style="color: red;">N'.'</span> <span style="color: gray;">+</span> coalesce<span style="color: gray;">(</span>quotename<span style="color: gray;">(</span>object_schema_name<span style="color: gray;">(</span><span style="color: teal;">PS</span><span style="color: gray;">.</span>object_id<span style="color: gray;">,</span> <span style="color: teal;">D</span><span style="color: gray;">.</span><span style="color: teal;">database_id</span><span style="color: gray;">)),</span> <span style="color: red;">N'-'</span><span style="color: gray;">)</span> <span style="color: gray;">+</span> <span style="color: red;">N'.'</span> <span style="color: gray;">+</span> coalesce<span style="color: gray;">(</span>quotename<span style="color: gray;">(</span>object_name<span style="color: gray;">(</span><span style="color: teal;">PS</span><span style="color: gray;">.</span>object_id<span style="color: gray;">,</span> <span style="color: teal;">D</span><span style="color: gray;">.</span><span style="color: teal;">database_id</span><span style="color: gray;">)),</span> <span style="color: red;">N'-'</span><span style="color: gray;">)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br /> <span style="color: blue;">order</span> <span style="color: blue;">by</span> <span style="color: teal;">[Size (MB)]</span> <span style="color: blue;">desc</span></p>
<h1>Processor</h1>
<p class="MsoNoSpacing">Most SQL Server application performance issues are related to storage bandwidth. However, occasionally computation bandwidth becomes an issue.</p>
<h2>Module processor usage</h2>
<p class="MsoNoSpacing">Here is a query to find the modules that are the most computationally expensive.</p>
<p class="Codenospacing"><span style="color: blue;">select</span> <span style="color: blue;">top</span><span style="color: gray;">(</span>10<span style="color: gray;">)</span> <span style="color: fuchsia;">convert</span><span style="color: gray;">(</span><span style="color: blue;">decimal</span><span style="color: gray;">(</span>38<span style="color: gray;">,</span> 6<span style="color: gray;">),</span> D<span style="color: gray;">.</span>total_worker_time<span style="color: gray;">)/</span>1000000 <span style="color: blue;">as</span> [CPU (secs)]<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; D<span style="color: gray;">.</span>execution_count <span style="color: blue;">as</span> [Executions]<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: fuchsia;">coalesce</span><span style="color: gray;">(</span><span style="color: fuchsia;">quotename</span><span style="color: gray;">(</span><span style="color: fuchsia;">db_name</span><span style="color: gray;">(</span>D<span style="color: gray;">.</span>database_id<span style="color: gray;">)),</span> <span style="color: red;">N'-'</span><span style="color: gray;">)</span> <span style="color: gray;">+</span> <span style="color: red;">N'.'</span> <span style="color: gray;">+</span> <span style="color: fuchsia;">coalesce</span><span style="color: gray;">(</span><span style="color: fuchsia;">quotename</span><span style="color: gray;">(</span><span style="color: fuchsia;">object_schema_name</span><span style="color: gray;">(</span>D<span style="color: gray;">.</span><span style="color: fuchsia;">object_id</span><span style="color: gray;">,</span> D<span style="color: gray;">.</span>database_id<span style="color: gray;">)),</span> <span style="color: red;">N'-'</span><span style="color: gray;">)</span> <span style="color: gray;">+</span> <span style="color: red;">N'.'</span> <span style="color: gray;">+</span> <span style="color: fuchsia;">coalesce</span><span style="color: gray;">(</span><span style="color: fuchsia;">quotename</span><span style="color: gray;">(</span><span style="color: fuchsia;">object_name</span><span style="color: gray;">(</span>D<span style="color: gray;">.</span><span style="color: fuchsia;">object_id</span><span style="color: gray;">,</span> D<span style="color: gray;">.</span>database_id<span style="color: gray;">)),</span> <span style="color: red;">N'-'</span><span style="color: gray;">)</span> <span style="color: blue;">as</span> [Module]<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; QP<span style="color: gray;">.</span>query_plan <span style="color: blue;">as</span> [Query plan]<br /> <span style="color: blue;">from</span> <span style="color: green;">sys</span><span style="color: gray;">.</span><span style="color: green;">dm_exec_procedure_stats</span> <span style="color: blue;">as</span> D<br /> &nbsp;&nbsp;&nbsp;&nbsp; <span style="color: gray;">outer</span> <span style="color: gray;">apply</span> <span style="color: green;">sys</span><span style="color: gray;">.</span><span style="color: green;">dm_exec_query_plan</span><span style="color: gray;">(</span>D<span style="color: gray;">.</span>plan_handle<span style="color: gray;">)</span> <span style="color: blue;">as</span> QP<br /> <span style="color: green;">--where D.database_id = db_id()<br /> </span><span style="color: blue;">order</span> <span style="color: blue;">by</span> D<span style="color: gray;">.</span>total_worker_time <span style="color: blue;">desc</span><span style="color: gray;">;</span></p>
<h2>Statement usage</h2>
<p class="MsoNoSpacing">Here is a query to find the statements that are the most computationally expensive.</p>
<p class="Codenospacing"><span style="color: blue;">select</span> <span style="color: blue;">top</span><span style="color: gray;">(</span>10<span style="color: gray;">)</span> <span style="color: fuchsia;">sum</span><span style="color: gray;">(</span><span style="color: fuchsia;">convert</span><span style="color: gray;">(</span><span style="color: blue;">decimal</span><span style="color: gray;">(</span>38<span style="color: gray;">,</span> 6<span style="color: gray;">),</span> Q<span style="color: gray;">.</span>total_worker_time<span style="color: gray;">)/</span>1000000<span style="color: gray;">)</span> <span style="color: blue;">as</span> [CPU (secs)]<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: fuchsia;">sum</span><span style="color: gray;">(</span>Q<span style="color: gray;">.</span>execution_count<span style="color: gray;">)</span> <span style="color: blue;">as</span> [Execution count]<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: fuchsia;">min</span><span style="color: gray;">(</span><span style="color: fuchsia;">coalesce</span><span style="color: gray;">(</span><span style="color: fuchsia;">quotename</span><span style="color: gray;">(</span><span style="color: fuchsia;">db_name</span><span style="color: gray;">(</span>Q<span style="color: gray;">.</span><span style="color: blue;">dbid</span><span style="color: gray;">)),</span> <span style="color: red;">N'-'</span><span style="color: gray;">)</span> <span style="color: gray;">+</span> <span style="color: red;">N'.'</span> <span style="color: gray;">+</span> <span style="color: fuchsia;">coalesce</span><span style="color: gray;">(</span><span style="color: fuchsia;">quotename</span><span style="color: gray;">(</span><span style="color: fuchsia;">object_schema_name</span><span style="color: gray;">(</span>Q<span style="color: gray;">.</span>objectid<span style="color: gray;">,</span> Q<span style="color: gray;">.</span><span style="color: blue;">dbid</span><span style="color: gray;">)),</span> <span style="color: red;">N'-'</span><span style="color: gray;">)</span> <span style="color: gray;">+</span> <span style="color: red;">N'.'</span> <span style="color: gray;">+</span> <span style="color: fuchsia;">coalesce</span><span style="color: gray;">(</span><span style="color: fuchsia;">quotename</span><span style="color: gray;">(</span><span style="color: fuchsia;">object_name</span><span style="color: gray;">(</span>Q<span style="color: gray;">.</span>objectid<span style="color: gray;">,</span> Q<span style="color: gray;">.</span><span style="color: blue;">dbid</span><span style="color: gray;">)),</span> <span style="color: red;">N'-'</span><span style="color: gray;">))</span> <span style="color: blue;">as</span> [Module]<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: fuchsia;">min</span><span style="color: gray;">(</span>Q<span style="color: gray;">.</span>statement_text<span style="color: gray;">)</span> <span style="color: blue;">as</span> [Statement]<br /> <span style="color: blue;">from </span><span style="color: gray;">(</span><span style="color: blue;">select</span> QS<span style="color: gray;">.*,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ST<span style="color: gray;">.</span><span style="color: blue;">dbid</span> <span style="color: blue;">as</span> <span style="color: blue;">dbid</span><span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ST<span style="color: gray;">.</span>objectid <span style="color: blue;">as</span> objectid<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: fuchsia;">substring</span><span style="color: gray;">(</span>ST<span style="color: gray;">.</span><span style="color: blue;">text</span><span style="color: gray;">,<br /> </span><span style="color: blue;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: gray;">(</span>QS<span style="color: gray;">.</span>statement_start_offset<span style="color: gray;">/</span>2<span style="color: gray;">)</span> <span style="color: gray;">+</span> 1<span style="color: gray;">,<br /> </span><span style="color: blue;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: gray;">((</span><span style="color: blue;">case</span> statement_end_offset <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">when</span> <span style="color: gray;">-</span>1 <span style="color: blue;">then</span> <span style="color: fuchsia;">datalength</span><span style="color: gray;">(</span>ST<span style="color: gray;">.</span><span style="color: blue;">text</span><span style="color: gray;">)<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">else</span> QS<span style="color: gray;">.</span>statement_end_offset <span style="color: blue;">end</span> <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: gray;">-</span> QS<span style="color: gray;">.</span>statement_start_offset<span style="color: gray;">)/</span>2<span style="color: gray;">)</span> <span style="color: gray;">+</span> 1<span style="color: gray;">)</span> <span style="color: blue;">as</span> statement_text<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">from</span> <span style="color: green;">sys</span><span style="color: gray;">.</span><span style="color: green;">dm_exec_query_stats</span> <span style="color: blue;">as</span> QS<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: gray;">cross</span> <span style="color: gray;">apply</span> <span style="color: green;">sys</span><span style="color: gray;">.</span><span style="color: green;">dm_exec_sql_text</span><span style="color: gray;">(</span>QS<span style="color: gray;">.</span><span style="color: blue;">sql_handle</span><span style="color: gray;">)</span> <span style="color: blue;">as</span> ST<span style="color: gray;">)</span> <span style="color: blue;">as</span> Q<br /> <span style="color: green;">--where Q.dbid = db_id()<br /> </span><span style="color: blue;">group</span> <span style="color: blue;">by</span> Q<span style="color: gray;">.</span>query_hash<br /> <span style="color: blue;">order</span> <span style="color: blue;">by</span> [CPU (secs)] <span style="color: blue;">desc</span><span style="color: gray;">;</span></p>
<h1>Waits</h1>
<p class="MsoNormal">Some SQL Server resources cannot be used concurrently. SQL Server uses various mechanisms to control usage of these resources. When one SQL Server process needs to use a resource that another is currently using it must wait for the resource to be freed. Thus one operation can cause another operation to take longer than it would otherwise take.</p>
<p class="MsoNoSpacing">Wait analysis requires some sophistication with the internals of SQL Server but is vital to performance tuning a high performance database application. To understand the resources in contention, during a time period, run the following statements at the beginning of the time period.</p>
<p class="Codenospacing"><span style="color: blue;">checkpoint</span><span style="color: gray;">;<br /> </span><span style="color: blue;">dbcc</span> freeproccache <span style="color: blue;">with</span> <span style="color: blue;">no_infomsgs</span><span style="color: gray;">;<br /> </span><span style="color: blue;">dbcc</span> dropcleanbuffers <span style="color: blue;">with</span> <span style="color: blue;">no_infomsgs</span><span style="color: gray;">;<br /> </span><span style="color: blue;">dbcc</span> sqlperf<span style="color: gray;">(</span><span style="color: red;">'sys.dm_os_wait_stats'</span><span style="color: gray;">,</span> <span style="color: blue;">clear</span><span style="color: gray;">);<br /> </span><span style="color: blue;">dbcc</span> sqlperf<span style="color: gray;">(</span><span style="color: red;">'sys.dm_os_latch_stats'</span><span style="color: gray;">,</span> <span style="color: blue;">clear</span><span style="color: gray;">);</span></p>
<p class="MsoNoSpacing">These statements reset internal counters and the state of the server to give more accurate results. At the end of the time period run the following query</p>
<p class="Codenospacing"><span style="color: blue;">select</span> <span style="color: red;">N'Lock total: '</span> <span style="color: gray;">+</span> WS<span style="color: gray;">.</span>wait_type <span style="color: blue;">as</span> [Type]<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; WS<span style="color: gray;">.</span>waiting_tasks_count <span style="color: blue;">as</span> [Waits (number)]<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: fuchsia;">convert</span><span style="color: gray;">(</span><span style="color: blue;">decimal</span><span style="color: gray;">(</span>38<span style="color: gray;">,</span>2<span style="color: gray;">),</span> WS<span style="color: gray;">.</span>wait_time_ms<span style="color: gray;">/</span>1000.0<span style="color: gray;">)</span> <span style="color: blue;">as</span> [Total wait time (secs)]<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; WS<span style="color: gray;">.</span>wait_time_ms<span style="color: gray;">/</span>WS<span style="color: gray;">.</span>waiting_tasks_count <span style="color: blue;">as</span> [Average wait time (ms)]<br /> <span style="color: blue;">from</span> <span style="color: green;">sys</span><span style="color: gray;">.</span><span style="color: green;">dm_os_wait_stats</span> <span style="color: blue;">as</span> WS<br /> <span style="color: blue;">where</span> WS<span style="color: gray;">.</span>waiting_tasks_count <span style="color: gray;">&gt;</span> 0<br /> <span style="color: blue;">union</span> <span style="color: gray;">all<br /> </span><span style="color: blue;">select</span> <span style="color: red;">N'Lock post signal: '</span> <span style="color: gray;">+</span> WS<span style="color: gray;">.</span>wait_type<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; WS<span style="color: gray;">.</span>waiting_tasks_count<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: fuchsia;">convert</span><span style="color: gray;">(</span><span style="color: blue;">decimal</span><span style="color: gray;">(</span>38<span style="color: gray;">,</span>2<span style="color: gray;">),</span> WS<span style="color: gray;">.</span>signal_wait_time_ms<span style="color: gray;">/</span>1000.0<span style="color: gray;">),<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; WS<span style="color: gray;">.</span>signal_wait_time_ms<span style="color: gray;">/</span>WS<span style="color: gray;">.</span>waiting_tasks_count<br /> <span style="color: blue;">from</span> <span style="color: green;">sys</span><span style="color: gray;">.</span><span style="color: green;">dm_os_wait_stats</span> <span style="color: blue;">as</span> WS<br /> <span style="color: blue;">where</span> WS<span style="color: gray;">.</span>waiting_tasks_count <span style="color: gray;">&gt;</span> 0<br /> <span style="color: blue;">union</span> <span style="color: gray;">all<br /> </span><span style="color: blue;">select</span> <span style="color: red;">N'Latch total: '</span> <span style="color: gray;">+</span> LS<span style="color: gray;">.</span>latch_class<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LS<span style="color: gray;">.</span>waiting_requests_count<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: fuchsia;">convert</span><span style="color: gray;">(</span><span style="color: blue;">decimal</span><span style="color: gray;">(</span>38<span style="color: gray;">,</span>2<span style="color: gray;">),</span> LS<span style="color: gray;">.</span>wait_time_ms<span style="color: gray;">/</span>1000.0<span style="color: gray;">),<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LS<span style="color: gray;">.</span>wait_time_ms<span style="color: gray;">/</span>LS<span style="color: gray;">.</span>waiting_requests_count<br /> <span style="color: blue;">from</span> <span style="color: green;">sys</span><span style="color: gray;">.</span><span style="color: green;">dm_os_latch_stats</span> <span style="color: blue;">as</span> LS<br /> <span style="color: blue;">where</span> LS<span style="color: gray;">.</span>waiting_requests_count <span style="color: gray;">&gt;</span> 0<br /> <span style="color: blue;">order</span> <span style="color: blue;">by</span> [Total wait time (secs)] <span style="color: blue;">desc</span><span style="color: gray;">;</span></p>
<p class="MsoNormal">See&nbsp;<a href="https://msdn.microsoft.com/en-us/library/ms179984.aspx">https://msdn.microsoft.com/en-us/library/ms179984.aspx</a> for a description of wait types. To run these two scripts you will need to be a member of either the sysadmin or serveradmin roles.</p>
<p class="MsoNormal">For a deep analysis, use the <a href="https://msdn.microsoft.com/en-us/performance/cc825801.aspx">Windows Performance Toolkit</a> to understand the deep behavior of a SQL Server application. SQL Server publishes data about its internals through ETW and this data can be combined with other ETW traces to build a detailed understanding of resource contention issues.</p>
<p class="MsoNoSpacing">Wait analysis can be useful in troubleshooting the cause of latency in a database application. The following script reports which statements are blocking other statements (i.e. using a resource the blocked statement is waiting for).</p>
<p class="Codenospacing"><span style="color: blue;">set</span> <span style="color: blue;">nocount</span> <span style="color: blue;">on</span><span style="color: gray;">;<br /> <br /> </span><span style="color: blue;">while</span> 1<span style="color: gray;">=</span>1<br /> <span style="color: blue;">begin<br /> </span>&nbsp;&nbsp;&nbsp; <span style="color: blue;">declare</span> @results <span style="color: blue;">table </span><span style="color: gray;">(<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [Id]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">int</span> <span style="color: blue;">identity</span> <span style="color: gray;">not</span> <span style="color: gray;">null</span> <span style="color: blue;">primary</span> <span style="color: blue;">key</span><span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [Blocked module]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">nvarchar</span><span style="color: gray;">(</span>776<span style="color: gray;">)</span> <span style="color: gray;">not</span> <span style="color: gray;">null,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [Blocked statement]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">nvarchar</span><span style="color: gray;">(</span><span style="color: fuchsia;">max</span><span style="color: gray;">)</span> <span style="color: gray;">not</span> <span style="color: gray;">null,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [Blocking module]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">nvarchar</span><span style="color: gray;">(</span>776<span style="color: gray;">)</span> <span style="color: gray;">null,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [Blocking statement]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">nvarchar</span><span style="color: gray;">(</span><span style="color: fuchsia;">max</span><span style="color: gray;">)</span> <span style="color: gray;">null,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [Wait type]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">nvarchar</span><span style="color: gray;">(</span>60<span style="color: gray;">)</span> <span style="color: gray;">not</span> <span style="color: gray;">null,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [Total wait time (MS)]&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">bigint</span> <span style="color: gray;">not</span> <span style="color: gray;">null,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [Sessions waiting (count)] <span style="color: blue;">int</span> <span style="color: gray;">not</span> <span style="color: gray;">null<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: gray;">);<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br /> &nbsp;&nbsp;&nbsp; <span style="color: blue;">delete</span> <span style="color: blue;">from</span> @results<span style="color: gray;">;<br /> </span>&nbsp;&nbsp;&nbsp; <br /> &nbsp;&nbsp;&nbsp; <span style="color: blue;">with</span> Statements<span style="color: gray;">(</span>[Blocked module]<span style="color: gray;">,</span> [Blocked statement start]<span style="color: gray;">,</span> [Blocked statement end]<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [Blocking module]<span style="color: gray;">,</span> [Blocking statement start]<span style="color: gray;">,</span> [Blocking statement end]<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [Wait type]<span style="color: gray;">,</span> [Total wait time (MS)]<span style="color: gray;">,</span> [Sessions waiting (count)]<span style="color: gray;">)<br /> </span>&nbsp;&nbsp;&nbsp; <span style="color: blue;">as<br /> &nbsp;&nbsp;&nbsp; </span><span style="color: gray;">(<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">select</span> BlockedR<span style="color: gray;">.</span><span style="color: blue;">sql_handle</span> <span style="color: blue;">as</span> [Blocked Module]<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; BlockedR<span style="color: gray;">.</span>statement_start_offset <span style="color: blue;">as</span> [Blocked Statement start]<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; BlockedR<span style="color: gray;">.</span>statement_end_offset <span style="color: blue;">as</span> [Blocked Statement end]<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; BlockingR<span style="color: gray;">.</span><span style="color: blue;">sql_handle</span> <span style="color: blue;">as</span> [Blocking Module]<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; BlockingR<span style="color: gray;">.</span>statement_start_offset <span style="color: blue;">as</span> [Blocking statement start]<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; BlockingR<span style="color: gray;">.</span>statement_end_offset <span style="color: blue;">as</span> [Blocking statement end]<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; WT<span style="color: gray;">.</span>wait_type <span style="color: blue;">as</span> [Wait type]<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: fuchsia;">sum</span><span style="color: gray;">(</span><span style="color: fuchsia;">convert</span><span style="color: gray;">(</span><span style="color: blue;">bigint</span><span style="color: gray;">,</span> WT<span style="color: gray;">.</span>wait_duration_ms<span style="color: gray;">))</span> <span style="color: blue;">as</span> [Total wait time (MS)]<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: fuchsia;">count</span><span style="color: gray;">(*)</span> <span style="color: blue;">as</span> [Sessions waiting (count)]<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">from</span> <span style="color: green;">sys</span><span style="color: gray;">.</span><span style="color: green;">dm_os_waiting_tasks</span> <span style="color: blue;">as</span> WT<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: gray;">inner</span> <span style="color: gray;">join</span> <span style="color: green;">sys</span><span style="color: gray;">.</span><span style="color: green;">dm_exec_requests</span> <span style="color: blue;">as</span> BlockedR <span style="color: blue;">on</span> BlockedR<span style="color: gray;">.</span>session_id <span style="color: gray;">=</span> WT<span style="color: gray;">.</span>session_id<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: gray;">left</span> <span style="color: gray;">outer</span> <span style="color: gray;">join</span> <span style="color: green;">sys</span><span style="color: gray;">.</span><span style="color: green;">dm_exec_requests</span> <span style="color: blue;">as</span> BlockingR <span style="color: blue;">on</span> BlockingR<span style="color: gray;">.</span>session_id <span style="color: gray;">=</span> WT<span style="color: gray;">.</span>blocking_session_id<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">group</span> <span style="color: blue;">by</span> BlockedR<span style="color: gray;">.</span><span style="color: blue;">sql_handle</span><span style="color: gray;">,</span> BlockedR<span style="color: gray;">.</span>statement_start_offset<span style="color: gray;">,</span> BlockedR<span style="color: gray;">.</span>statement_end_offset<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; BlockingR<span style="color: gray;">.</span><span style="color: blue;">sql_handle</span><span style="color: gray;">,</span> BlockingR<span style="color: gray;">.</span>statement_start_offset<span style="color: gray;">,</span> BlockingR<span style="color: gray;">.</span>statement_end_offset<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; WT<span style="color: gray;">.</span>wait_type<br /> &nbsp;&nbsp;&nbsp; <span style="color: gray;">)<br /> </span>&nbsp;&nbsp;&nbsp; <span style="color: blue;">insert</span> <span style="color: blue;">into</span> @results<span style="color: gray;">(</span>[Blocked module]<span style="color: gray;">,</span> [Blocked statement]<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [Blocking module]<span style="color: gray;">,</span> [Blocking statement]<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [Wait type]<span style="color: gray;">,</span> [Total wait time (MS)]<span style="color: gray;">,</span> [Sessions waiting (count)]<span style="color: gray;">)<br /> </span>&nbsp;&nbsp;&nbsp; <span style="color: blue;">select</span> <span style="color: fuchsia;">coalesce</span><span style="color: gray;">(</span><span style="color: fuchsia;">quotename</span><span style="color: gray;">(</span><span style="color: fuchsia;">db_name</span><span style="color: gray;">(</span>BlockedText<span style="color: gray;">.</span><span style="color: blue;">dbid</span><span style="color: gray;">)),</span> <span style="color: red;">N'-'</span><span style="color: gray;">)</span> <span style="color: gray;">+</span> <span style="color: red;">N'.'</span> <span style="color: gray;">+</span> <span style="color: fuchsia;">coalesce</span><span style="color: gray;">(</span><span style="color: fuchsia;">quotename</span><span style="color: gray;">(</span><span style="color: fuchsia;">object_schema_name</span><span style="color: gray;">(</span>BlockedText<span style="color: gray;">.</span>objectid<span style="color: gray;">,</span> BlockedText<span style="color: gray;">.</span><span style="color: blue;">dbid</span><span style="color: gray;">)),</span> <span style="color: red;">N'-'</span><span style="color: gray;">)</span> <span style="color: gray;">+</span> <span style="color: red;">N'.'</span> <span style="color: gray;">+</span> <span style="color: fuchsia;">coalesce</span><span style="color: gray;">(</span><span style="color: fuchsia;">quotename</span><span style="color: gray;">(</span><span style="color: fuchsia;">object_name</span><span style="color: gray;">(</span>BlockedText<span style="color: gray;">.</span>objectid<span style="color: gray;">,</span> BlockedText<span style="color: gray;">.</span><span style="color: blue;">dbid</span><span style="color: gray;">)),</span> <span style="color: red;">N'-'</span><span style="color: gray;">)</span> <span style="color: blue;">as</span> [Blocked module]<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: fuchsia;">substring</span><span style="color: gray;">(</span>BlockedText<span style="color: gray;">.</span><span style="color: blue;">text</span><span style="color: gray;">,<br /> </span><span style="color: blue;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: gray;">(</span>S<span style="color: gray;">.</span>[Blocked statement start]<span style="color: gray;">/</span>2<span style="color: gray;">)</span> <span style="color: gray;">+</span> 1<span style="color: gray;">,<br /> </span><span style="color: blue;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: gray;">((</span><span style="color: blue;">case</span> S<span style="color: gray;">.</span>[Blocked statement end] <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">when</span> <span style="color: gray;">-</span>1 <span style="color: blue;">then</span> <span style="color: fuchsia;">datalength</span><span style="color: gray;">(</span>BlockingText<span style="color: gray;">.</span><span style="color: blue;">text</span><span style="color: gray;">)<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">else</span> S<span style="color: gray;">.</span>[Blocked statement end]<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">end</span> <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: gray;">-</span> S<span style="color: gray;">.</span>[Blocked statement start]<span style="color: gray;">)/</span>2<span style="color: gray;">)</span> <span style="color: gray;">+</span> 1<span style="color: gray;">)</span> <span style="color: blue;">as</span> [Blocked statement]<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: fuchsia;">coalesce</span><span style="color: gray;">(</span><span style="color: fuchsia;">quotename</span><span style="color: gray;">(</span><span style="color: fuchsia;">db_name</span><span style="color: gray;">(</span>BlockingText<span style="color: gray;">.</span><span style="color: blue;">dbid</span><span style="color: gray;">)),</span> <span style="color: red;">N'-'</span><span style="color: gray;">)</span> <span style="color: gray;">+</span> <span style="color: red;">N'.'</span> <span style="color: gray;">+</span> <span style="color: fuchsia;">coalesce</span><span style="color: gray;">(</span><span style="color: fuchsia;">quotename</span><span style="color: gray;">(</span><span style="color: fuchsia;">object_schema_name</span><span style="color: gray;">(</span>BlockingText<span style="color: gray;">.</span>objectid<span style="color: gray;">,</span> BlockingText<span style="color: gray;">.</span><span style="color: blue;">dbid</span><span style="color: gray;">)),</span> <span style="color: red;">N'-'</span><span style="color: gray;">)</span> <span style="color: gray;">+</span> <span style="color: red;">N'.'</span> <span style="color: gray;">+</span> <span style="color: fuchsia;">coalesce</span><span style="color: gray;">(</span><span style="color: fuchsia;">quotename</span><span style="color: gray;">(</span><span style="color: fuchsia;">object_name</span><span style="color: gray;">(</span>BlockingText<span style="color: gray;">.</span>objectid<span style="color: gray;">,</span> BlockingText<span style="color: gray;">.</span><span style="color: blue;">dbid</span><span style="color: gray;">)),</span> <span style="color: red;">N'-'</span><span style="color: gray;">)</span> <span style="color: blue;">as</span> [Blocking module]<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: fuchsia;">substring</span><span style="color: gray;">(</span>BlockingText<span style="color: gray;">.</span><span style="color: blue;">text</span><span style="color: gray;">,<br /> </span><span style="color: blue;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: gray;">(</span>S<span style="color: gray;">.</span>[Blocking statement start]<span style="color: gray;">/</span>2<span style="color: gray;">)</span> <span style="color: gray;">+</span> 1<span style="color: gray;">,<br /> </span><span style="color: blue;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: gray;">((</span><span style="color: blue;">case</span> S<span style="color: gray;">.</span>[Blocking statement end] <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">when</span> <span style="color: gray;">-</span>1 <span style="color: blue;">then</span> <span style="color: fuchsia;">datalength</span><span style="color: gray;">(</span>BlockingText<span style="color: gray;">.</span><span style="color: blue;">text</span><span style="color: gray;">)<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">else</span> S<span style="color: gray;">.</span>[Blocking statement end]<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">end</span> <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: gray;">-</span> S<span style="color: gray;">.</span>[Blocking statement start]<span style="color: gray;">)/</span>2<span style="color: gray;">)</span> <span style="color: gray;">+</span> 1<span style="color: gray;">)</span> <span style="color: blue;">as</span> [Blocking statement]<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; S<span style="color: gray;">.</span>[Wait type] <span style="color: blue;">as</span> [Wait type]<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; S<span style="color: gray;">.</span>[Total wait time (MS)] <span style="color: blue;">as</span> [Total wait time (MS)]<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; S<span style="color: gray;">.</span>[Sessions waiting (count)] <span style="color: blue;">as</span> [Sessions waiting (count)]<br /> &nbsp;&nbsp;&nbsp; <span style="color: blue;">from</span> Statements <span style="color: blue;">as</span> S<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: gray;">cross</span> <span style="color: gray;">apply</span> <span style="color: green;">sys</span><span style="color: gray;">.</span><span style="color: green;">dm_exec_sql_text</span><span style="color: gray;">(</span>S<span style="color: gray;">.</span>[Blocked module]<span style="color: gray;">)</span> <span style="color: blue;">as</span> BlockedText<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: gray;">cross</span> <span style="color: gray;">apply</span> <span style="color: green;">sys</span><span style="color: gray;">.</span><span style="color: green;">dm_exec_sql_text</span><span style="color: gray;">(</span>S<span style="color: gray;">.</span>[Blocking module]<span style="color: gray;">)</span> <span style="color: blue;">as</span> BlockingText<br /> &nbsp;&nbsp;&nbsp; <span style="color: green;">--where S.[Total wait time (MS)] &gt; 50<br /> </span>&nbsp;&nbsp;&nbsp; <span style="color: blue;">order</span> <span style="color: blue;">by</span> S<span style="color: gray;">.</span>[Total wait time (MS)] <span style="color: blue;">desc<br /> </span>&nbsp;&nbsp;&nbsp; <span style="color: blue;">option </span><span style="color: gray;">(</span><span style="color: blue;">force</span> <span style="color: blue;">order</span><span style="color: gray;">);<br /> </span><br /> &nbsp;&nbsp;&nbsp; <span style="color: blue;">if</span> <span style="color: gray;">exists</span><span style="color: gray;">(</span><span style="color: blue;">select</span> <span style="color: gray;">*</span> <span style="color: blue;">from</span> @results<span style="color: gray;">)<br /> </span>&nbsp;&nbsp;&nbsp; <span style="color: blue;">begin<br /> </span>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;<span style="color: blue;">select</span> <span style="color: fuchsia;">getdate</span><span style="color: gray;">(),<br /> </span>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[Blocked module]<span style="color: gray;">,</span> [Blocked statement]<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [Blocking module]<span style="color: gray;">,</span> [Blocking statement]<span style="color: gray;">,<br /> </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [Wait type]<span style="color: gray;">,</span> [Total wait time (MS)]<span style="color: gray;">,</span> [Sessions waiting (count)]<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;<span style="color: blue;">from</span> @results<span style="color: gray;">;<br /> </span>&nbsp;&nbsp;&nbsp; <span style="color: blue;">end</span><span style="color: gray;">;<br /> </span><br /> &nbsp;&nbsp;&nbsp; <span style="color: blue;">waitfor</span> <span style="color: blue;">delay</span> <span style="color: red;">'00:00:01'<br /> </span><span style="color: blue;">end</span></p>
<p class="MsoNormal">Every second the script reports the blocked and blocking statements. Care is needed in interpreting the report because a blocked statement may itself be blocked waiting for another resource.</p>
<h1>Script</h1>
<p class="MsoNoSpacing">The downloadable T-SQL script contains the above queries and some less commonly used scripts for:</p>
<p class="MsoListBulletCxSpFirst"><span style="font-family: Symbol;">&middot;<span style="font: 7.0pt 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span>Finding the databases that have the highest read volumes.</p>
<p class="MsoListBulletCxSpMiddle"><span style="font-family: Symbol;">&middot;<span style="font: 7.0pt 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span>Finding the databases that have the highest write volumes.</p>
<p class="MsoListBulletCxSpMiddle"><span style="font-family: Symbol;">&middot;<span style="font: 7.0pt 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span>Finding the total SQL Server instance read and write volume.</p>
<p class="MsoListBulletCxSpLast"><span style="font-family: Symbol;">&middot;<span style="font: 7.0pt 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span>The modules that are recompiled the most.</p>
</div>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Components.PostAttachments/00/10/37/56/95/Performance%20investigation.sql" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-components-postattachments/00-10-37-56-95/Performance-investigation.sql">Performance investigation.sql</a></p>]]></content:encoded>
    </item>
    <item>
      <title>Implementing uniqueness constraints on large columns</title>
      <link>https://docs.microsoft.com/archive/blogs/anthonybloesch/implementing-uniqueness-constraints-on-large-columns</link>
      <pubDate>Mon, 23 Nov 2009 10:01:00 GMT</pubDate>
      <dc:creator><![CDATA[Anthony Bloesch]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/anthonybloesch/2009/11/23/implementing-uniqueness-constraints-on-large-columns/</guid>
      <description><![CDATA[SQL Server uniqueness constraints create an underlying unique index. SQL Server index keys may not...]]></description>
      <content:encoded><![CDATA[<P mce_keep="true">SQL Server uniqueness constraints create an underlying unique index. SQL Server index keys may not be more than 900 bytes. Below I discuss how to implement uniqueness constraints with hash indexes when the key size can exceed 900 bytes and give the results of some tests on the relative performance of the hash index approach. </P>
<H2>Calculating the size of an index </H2>
<P class=MsoNoSpacing>If there are variable length columns, SQL Server may allow the uniqueness constraint to be created but oversized rows will not be insertable. Below is a formula to determine when an index may overflow the 900 byte limit. The maximum size of a unique constraint index key can be calculated using Table <SPAN style="mso-no-proof: yes">1</SPAN> as: </P>
<P mce_keep="true"><SPAN style="LINE-HEIGHT: 110%; FONT-FAMILY: 'Cambria','serif'; FONT-SIZE: 11pt; mso-fareast-font-family: calibri; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-fareast-language: en-us; mso-bidi-language: ar-sa"><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image002_4.png" original-url="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image002_4.png" mce_href="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image002_4.png"><IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: block; FLOAT: none; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; MARGIN-LEFT: auto; BORDER-LEFT-WIDTH: 0px; MARGIN-RIGHT: auto" title=clip_image002 border=0 alt=clip_image002 src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image002_thumb_1.png" original-url="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image002_thumb_1.png" width=179 height=52 v:shapes="_x0000_i1025" mce_src="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image002_thumb_1.png"></A></SPAN>&nbsp;where <SPAN style="POSITION: relative; LINE-HEIGHT: 110%; FONT-FAMILY: 'Cambria','serif'; FONT-SIZE: 11pt; TOP: 4pt; mso-fareast-font-family: calibri; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-fareast-language: en-us; mso-bidi-language: ar-sa; mso-text-raise: -4.0pt"><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image004_6.png" original-url="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image004_6.png" mce_href="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image004_6.png"><IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=clip_image004 border=0 alt=clip_image004 src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image004_thumb_1.png" original-url="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image004_thumb_1.png" width=8 height=19 v:shapes="_x0000_i1025" mce_src="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image004_thumb_1.png"></A></SPAN><SPAN style="mso-spacerun: yes">&nbsp;</SPAN>is the overhead, <SPAN style="POSITION: relative; LINE-HEIGHT: 110%; FONT-FAMILY: 'Cambria','serif'; FONT-SIZE: 11pt; TOP: 4.5pt; mso-fareast-font-family: calibri; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-fareast-language: en-us; mso-bidi-language: ar-sa; mso-text-raise: -4.5pt"><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image006_4.png" original-url="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image006_4.png" mce_href="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image006_4.png"><IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=clip_image006 border=0 alt=clip_image006 src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image006_thumb_1.png" original-url="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image006_thumb_1.png" width=29 height=19 v:shapes="_x0000_i1025" mce_src="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image006_thumb_1.png"></A></SPAN><SPAN style="mso-spacerun: yes">&nbsp;</SPAN>is the variable sized column overhead for <SPAN style="POSITION: relative; LINE-HEIGHT: 110%; FONT-FAMILY: 'Cambria','serif'; FONT-SIZE: 11pt; TOP: 4pt; mso-fareast-font-family: calibri; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-fareast-language: en-us; mso-bidi-language: ar-sa; mso-text-raise: -4.0pt"><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image008_14.png" original-url="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image008_14.png" mce_href="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image008_14.png"><IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=clip_image008 border=0 alt=clip_image008 src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image008_thumb_1.png" original-url="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image008_thumb_1.png" width=9 height=19 v:shapes="_x0000_i1025" mce_src="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image008_thumb_1.png"></A></SPAN><SPAN style="mso-spacerun: yes">&nbsp;</SPAN>variable sized columns, <SPAN style="POSITION: relative; LINE-HEIGHT: 110%; FONT-FAMILY: 'Cambria','serif'; FONT-SIZE: 11pt; TOP: 4.5pt; mso-fareast-font-family: calibri; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-fareast-language: en-us; mso-bidi-language: ar-sa; mso-text-raise: -4.5pt"><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image010_4.png" original-url="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image010_4.png" mce_href="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image010_4.png"><IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=clip_image010 border=0 alt=clip_image010 src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image010_thumb_1.png" original-url="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image010_thumb_1.png" width=30 height=19 v:shapes="_x0000_i1025" mce_src="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image010_thumb_1.png"></A></SPAN><SPAN style="mso-spacerun: yes">&nbsp;</SPAN>is the nullable column overhead for <SPAN style="POSITION: relative; LINE-HEIGHT: 110%; FONT-FAMILY: 'Cambria','serif'; FONT-SIZE: 11pt; TOP: 4pt; mso-fareast-font-family: calibri; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-fareast-language: en-us; mso-bidi-language: ar-sa; mso-text-raise: -4.0pt"><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image008_16.png" original-url="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image008_16.png" mce_href="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image008_16.png"><IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=clip_image008 border=0 alt=clip_image008 src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image008_thumb_2.png" original-url="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image008_thumb_2.png" width=9 height=19 v:shapes="_x0000_i1025" mce_src="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image008_thumb_2.png"></A></SPAN><SPAN style="mso-spacerun: yes">&nbsp;</SPAN>nullable columns, <SPAN style="POSITION: relative; LINE-HEIGHT: 110%; FONT-FAMILY: 'Cambria','serif'; FONT-SIZE: 11pt; TOP: 4.5pt; mso-fareast-font-family: calibri; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-fareast-language: en-us; mso-bidi-language: ar-sa; mso-text-raise: -4.5pt"><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image012_4.png" original-url="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image012_4.png" mce_href="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image012_4.png"><IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=clip_image012 border=0 alt=clip_image012 src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image012_thumb_1.png" original-url="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image012_thumb_1.png" width=23 height=19 v:shapes="_x0000_i1025" mce_src="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image012_thumb_1.png"></A></SPAN><SPAN style="mso-spacerun: yes">&nbsp;</SPAN>is the type cost for column <SPAN style="POSITION: relative; LINE-HEIGHT: 110%; FONT-FAMILY: 'Cambria','serif'; FONT-SIZE: 11pt; TOP: 4pt; mso-fareast-font-family: calibri; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-fareast-language: en-us; mso-bidi-language: ar-sa; mso-text-raise: -4.0pt"><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image014_4.png" original-url="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image014_4.png" mce_href="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image014_4.png"><IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=clip_image014 border=0 alt=clip_image014 src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image014_thumb_1.png" original-url="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image014_thumb_1.png" width=9 height=23 v:shapes="_x0000_i1025" mce_src="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image014_thumb_1.png"></A></SPAN>, <SPAN style="POSITION: relative; LINE-HEIGHT: 110%; FONT-FAMILY: 'Cambria','serif'; FONT-SIZE: 11pt; TOP: 4.5pt; mso-fareast-font-family: calibri; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-fareast-language: en-us; mso-bidi-language: ar-sa; mso-text-raise: -4.5pt"><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image016_4.png" original-url="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image016_4.png" mce_href="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image016_4.png"><IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=clip_image016 border=0 alt=clip_image016 src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image016_thumb_1.png" original-url="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image016_thumb_1.png" width=15 height=19 v:shapes="_x0000_i1025" mce_src="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image016_thumb_1.png"></A></SPAN><SPAN style="mso-spacerun: yes">&nbsp;</SPAN>is the number of variable sized columns, <SPAN style="POSITION: relative; LINE-HEIGHT: 110%; FONT-FAMILY: 'Cambria','serif'; FONT-SIZE: 11pt; TOP: 4.5pt; mso-fareast-font-family: calibri; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-fareast-language: en-us; mso-bidi-language: ar-sa; mso-text-raise: -4.5pt"><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image018_4.png" original-url="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image018_4.png" mce_href="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image018_4.png"><IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=clip_image018 border=0 alt=clip_image018 src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image018_thumb_1.png" original-url="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image018_thumb_1.png" width=16 height=19 v:shapes="_x0000_i1025" mce_src="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image018_thumb_1.png"></A></SPAN>is the number of nullable columns and <SPAN style="POSITION: relative; LINE-HEIGHT: 110%; FONT-FAMILY: 'Cambria','serif'; FONT-SIZE: 11pt; TOP: 4.5pt; mso-fareast-font-family: calibri; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-fareast-language: en-us; mso-bidi-language: ar-sa; mso-text-raise: -4.5pt"><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image020_4.png" original-url="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image020_4.png" mce_href="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image020_4.png"><IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=clip_image020 border=0 alt=clip_image020 src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image020_thumb_1.png" original-url="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image020_thumb_1.png" width=15 height=19 v:shapes="_x0000_i1025" mce_src="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image020_thumb_1.png"></A></SPAN><SPAN style="mso-spacerun: yes">&nbsp;</SPAN>is the number of columns. The overhead <SPAN style="POSITION: relative; LINE-HEIGHT: 110%; FONT-FAMILY: 'Cambria','serif'; FONT-SIZE: 11pt; TOP: 4pt; mso-fareast-font-family: calibri; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-fareast-language: en-us; mso-bidi-language: ar-sa; mso-text-raise: -4.0pt"><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image004_8.png" original-url="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image004_8.png" mce_href="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image004_8.png"><IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=clip_image004 border=0 alt=clip_image004 src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image004_thumb_2.png" original-url="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image004_thumb_2.png" width=8 height=19 v:shapes="_x0000_i1025" mce_src="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image004_thumb_2.png"></A></SPAN><SPAN style="mso-spacerun: yes">&nbsp;</SPAN>varies depending on whether or not the underlying index is clustered (see Table <SPAN style="mso-no-proof: yes">1)</SPAN>. </P>
<BLOCKQUOTE>
<P style="PAGE-BREAK-AFTER: avoid" class=MsoCaption><A title=_Ref197518081 name=_Ref197518081></A>Table <SPAN style="mso-bookmark: _ref197518081"><SPAN style="mso-no-proof: yes">1</SPAN></SPAN><SPAN style="mso-bookmark: _ref197518081"></SPAN> Table of contributions to the size of an index key. To calculate the maximum size of an index key in bytes add the size of every column in the index key and the primary key and add the overhead. </P></BLOCKQUOTE>
<P mce_keep="true">&nbsp;</P>
<DIV align=center>
<TABLE style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; BORDER-COLLAPSE: collapse; BORDER-TOP: medium none; BORDER-RIGHT: medium none; mso-border-alt: solid windowtext .5pt; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt" class=MsoTableGrid border=1 cellSpacing=0 cellPadding=0 class="MsoTableGrid">
<THEAD>
<TR style="mso-yfti-irow: 0; mso-yfti-firstrow: yes">
<TD style="BORDER-BOTTOM: black 1pt solid; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-bottom-themecolor: text1; mso-border-bottom-alt: solid black .5pt; mso-border-right-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right><B style="mso-bidi-font-weight: normal">Object </B></P></TD>
<TD style="BORDER-BOTTOM: black 1pt solid; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: medium none; PADDING-TOP: 0in; mso-border-bottom-themecolor: text1; mso-border-bottom-alt: solid black .5pt; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: left; MARGIN-BOTTOM: 0pt" class=MsoNormal align=left><B style="mso-bidi-font-weight: normal">Size (bytes) </B></P></TD></TR></THEAD>
<TBODY>
<TR style="mso-yfti-irow: 1">
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right><SPAN style="mso-no-proof: yes">bigint </SPAN></P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: medium none; PADDING-TOP: 0in; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" vAlign=top>
<P style="MARGIN-BOTTOM: 0pt" class=MsoNormal>8 </P></TD></TR>
<TR style="mso-yfti-irow: 2">
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right><SPAN style="mso-no-proof: yes">binary(n) </SPAN></P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: medium none; PADDING-TOP: 0in; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="MARGIN-BOTTOM: 0pt" class=MsoNormal><SPAN style="LINE-HEIGHT: 110%; FONT-FAMILY: 'Cambria','serif'; FONT-SIZE: 11pt; mso-fareast-font-family: calibri; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-fareast-language: en-us; mso-bidi-language: ar-sa"><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image008_18.png" original-url="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image008_18.png" mce_href="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image008_18.png"><IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=clip_image008 border=0 alt=clip_image008 src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image008_thumb_3.png" original-url="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image008_thumb_3.png" width=9 height=19 v:shapes="_x0000_i1025" mce_src="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image008_thumb_3.png"></A></SPAN>&nbsp;</P></TD></TR>
<TR style="mso-yfti-irow: 3">
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right><SPAN style="mso-no-proof: yes">binary(max) </SPAN></P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: medium none; PADDING-TOP: 0in; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="MARGIN-BOTTOM: 0pt" class=MsoNormal><SPAN style="LINE-HEIGHT: 110%; FONT-FAMILY: 'Cambria','serif'; FONT-SIZE: 11pt; mso-fareast-font-family: calibri; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-fareast-language: en-us; mso-bidi-language: ar-sa"><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image024_22.png" original-url="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image024_22.png" mce_href="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image024_22.png"><IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=clip_image024 border=0 alt=clip_image024 src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image024_thumb_1.png" original-url="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image024_thumb_1.png" width=12 height=19 v:shapes="_x0000_i1025" mce_src="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image024_thumb_1.png"></A></SPAN>&nbsp;</P></TD></TR>
<TR style="mso-yfti-irow: 4">
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right><SPAN style="mso-no-proof: yes">bit </SPAN></P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: medium none; PADDING-TOP: 0in; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="MARGIN-BOTTOM: 0pt" class=MsoNormal>1 </P></TD></TR>
<TR style="mso-yfti-irow: 5">
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right><SPAN style="mso-no-proof: yes">char </SPAN></P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: medium none; PADDING-TOP: 0in; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="MARGIN-BOTTOM: 0pt" class=MsoNormal><SPAN style="LINE-HEIGHT: 110%; FONT-FAMILY: 'Cambria','serif'; FONT-SIZE: 11pt; mso-fareast-font-family: calibri; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-fareast-language: en-us; mso-bidi-language: ar-sa"><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image008_20.png" original-url="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image008_20.png" mce_href="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image008_20.png"><IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=clip_image008 border=0 alt=clip_image008 src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image008_thumb_4.png" original-url="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image008_thumb_4.png" width=9 height=19 v:shapes="_x0000_i1025" mce_src="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image008_thumb_4.png"></A></SPAN>&nbsp;</P></TD></TR>
<TR style="mso-yfti-irow: 6">
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right><SPAN style="mso-no-proof: yes">date </SPAN></P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: medium none; PADDING-TOP: 0in; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="MARGIN-BOTTOM: 0pt" class=MsoNormal>3 </P></TD></TR>
<TR style="mso-yfti-irow: 7">
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right><SPAN style="mso-no-proof: yes">datetime </SPAN></P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: medium none; PADDING-TOP: 0in; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="MARGIN-BOTTOM: 0pt" class=MsoNormal>8 </P></TD></TR>
<TR style="mso-yfti-irow: 8">
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right><SPAN style="mso-no-proof: yes">datetime2 </SPAN></P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: medium none; PADDING-TOP: 0in; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="MARGIN-BOTTOM: 0pt" class=MsoNormal>8 </P></TD></TR>
<TR style="mso-yfti-irow: 9">
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right><SPAN style="mso-no-proof: yes">datetimeoffset </SPAN></P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: medium none; PADDING-TOP: 0in; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="MARGIN-BOTTOM: 0pt" class=MsoNormal>10 </P></TD></TR>
<TR style="mso-yfti-irow: 10">
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right><SPAN style="mso-no-proof: yes">decimal </SPAN></P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: medium none; PADDING-TOP: 0in; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="MARGIN-BOTTOM: 0pt" class=MsoNormal>17 </P></TD></TR>
<TR style="mso-yfti-irow: 11">
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right><SPAN style="mso-no-proof: yes">float </SPAN></P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: medium none; PADDING-TOP: 0in; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="MARGIN-BOTTOM: 0pt" class=MsoNormal>8 </P></TD></TR>
<TR style="mso-yfti-irow: 12">
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right><SPAN style="mso-no-proof: yes">geography </SPAN></P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: medium none; PADDING-TOP: 0in; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="MARGIN-BOTTOM: 0pt" class=MsoNormal><SPAN style="LINE-HEIGHT: 110%; FONT-FAMILY: 'Cambria','serif'; FONT-SIZE: 11pt; mso-fareast-font-family: calibri; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-fareast-language: en-us; mso-bidi-language: ar-sa"><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image024_24.png" original-url="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image024_24.png" mce_href="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image024_24.png"><IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=clip_image024 border=0 alt=clip_image024 src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image024_thumb_2.png" original-url="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image024_thumb_2.png" width=12 height=19 v:shapes="_x0000_i1025" mce_src="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image024_thumb_2.png"></A></SPAN>&nbsp;</P></TD></TR>
<TR style="mso-yfti-irow: 13">
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right><SPAN style="mso-no-proof: yes">geometry </SPAN></P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: medium none; PADDING-TOP: 0in; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="MARGIN-BOTTOM: 0pt" class=MsoNormal><SPAN style="LINE-HEIGHT: 110%; FONT-FAMILY: 'Cambria','serif'; FONT-SIZE: 11pt; mso-fareast-font-family: calibri; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-fareast-language: en-us; mso-bidi-language: ar-sa"><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image024_26.png" original-url="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image024_26.png" mce_href="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image024_26.png"><IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=clip_image024 border=0 alt=clip_image024 src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image024_thumb_3.png" original-url="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image024_thumb_3.png" width=12 height=19 v:shapes="_x0000_i1025" mce_src="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image024_thumb_3.png"></A></SPAN>&nbsp;</P></TD></TR>
<TR style="mso-yfti-irow: 14">
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right><SPAN style="mso-no-proof: yes">hierarchyid </SPAN></P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: medium none; PADDING-TOP: 0in; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="MARGIN-BOTTOM: 0pt" class=MsoNormal>892 </P></TD></TR>
<TR style="mso-yfti-irow: 15">
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right><SPAN style="mso-no-proof: yes">image </SPAN></P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: medium none; PADDING-TOP: 0in; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="MARGIN-BOTTOM: 0pt" class=MsoNormal><SPAN style="LINE-HEIGHT: 110%; FONT-FAMILY: 'Cambria','serif'; FONT-SIZE: 11pt; mso-fareast-font-family: calibri; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-fareast-language: en-us; mso-bidi-language: ar-sa"><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image024_28.png" original-url="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image024_28.png" mce_href="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image024_28.png"><IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=clip_image024 border=0 alt=clip_image024 src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image024_thumb_4.png" original-url="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image024_thumb_4.png" width=12 height=19 v:shapes="_x0000_i1025" mce_src="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image024_thumb_4.png"></A></SPAN>&nbsp;</P></TD></TR>
<TR style="mso-yfti-irow: 16">
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right><SPAN style="mso-no-proof: yes">int </SPAN></P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: medium none; PADDING-TOP: 0in; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="MARGIN-BOTTOM: 0pt" class=MsoNormal>4 </P></TD></TR>
<TR style="mso-yfti-irow: 17">
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right><SPAN style="mso-no-proof: yes">money </SPAN></P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: medium none; PADDING-TOP: 0in; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="MARGIN-BOTTOM: 0pt" class=MsoNormal>8 </P></TD></TR>
<TR style="mso-yfti-irow: 18">
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right><SPAN style="mso-no-proof: yes">nchar(n) </SPAN></P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: medium none; PADDING-TOP: 0in; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="MARGIN-BOTTOM: 0pt" class=MsoNormal><SPAN style="LINE-HEIGHT: 110%; FONT-FAMILY: 'Cambria','serif'; FONT-SIZE: 11pt; mso-fareast-font-family: calibri; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-fareast-language: en-us; mso-bidi-language: ar-sa"><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image026_6.png" original-url="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image026_6.png" mce_href="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image026_6.png"><IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=clip_image026 border=0 alt=clip_image026 src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image026_thumb_1.png" original-url="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image026_thumb_1.png" width=34 height=19 v:shapes="_x0000_i1025" mce_src="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image026_thumb_1.png"></A></SPAN>&nbsp;</P></TD></TR>
<TR style="mso-yfti-irow: 19">
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right><SPAN style="mso-no-proof: yes">nchar(max) </SPAN></P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: medium none; PADDING-TOP: 0in; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="MARGIN-BOTTOM: 0pt" class=MsoNormal><SPAN style="LINE-HEIGHT: 110%; FONT-FAMILY: 'Cambria','serif'; FONT-SIZE: 11pt; mso-fareast-font-family: calibri; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-fareast-language: en-us; mso-bidi-language: ar-sa"><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image024_30.png" original-url="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image024_30.png" mce_href="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image024_30.png"><IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=clip_image024 border=0 alt=clip_image024 src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image024_thumb_5.png" original-url="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image024_thumb_5.png" width=12 height=19 v:shapes="_x0000_i1025" mce_src="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image024_thumb_5.png"></A></SPAN>&nbsp;</P></TD></TR>
<TR style="mso-yfti-irow: 20">
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right><SPAN style="mso-no-proof: yes">ntext </SPAN></P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: medium none; PADDING-TOP: 0in; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="MARGIN-BOTTOM: 0pt" class=MsoNormal><SPAN style="LINE-HEIGHT: 110%; FONT-FAMILY: 'Cambria','serif'; FONT-SIZE: 11pt; mso-fareast-font-family: calibri; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-fareast-language: en-us; mso-bidi-language: ar-sa"><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image024_32.png" original-url="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image024_32.png" mce_href="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image024_32.png"><IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=clip_image024 border=0 alt=clip_image024 src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image024_thumb_6.png" original-url="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image024_thumb_6.png" width=12 height=19 v:shapes="_x0000_i1025" mce_src="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image024_thumb_6.png"></A></SPAN>&nbsp;</P></TD></TR>
<TR style="mso-yfti-irow: 21">
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right><SPAN style="mso-no-proof: yes">numeric </SPAN></P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: medium none; PADDING-TOP: 0in; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="MARGIN-BOTTOM: 0pt" class=MsoNormal>17 </P></TD></TR>
<TR style="mso-yfti-irow: 22">
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right><SPAN style="mso-no-proof: yes">nvarchar(n) </SPAN></P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: medium none; PADDING-TOP: 0in; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="MARGIN-BOTTOM: 0pt" class=MsoNormal><SPAN style="LINE-HEIGHT: 110%; FONT-FAMILY: 'Cambria','serif'; FONT-SIZE: 11pt; mso-fareast-font-family: calibri; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-fareast-language: en-us; mso-bidi-language: ar-sa"><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image026_8.png" original-url="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image026_8.png" mce_href="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image026_8.png"><IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=clip_image026 border=0 alt=clip_image026 src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image026_thumb_2.png" original-url="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image026_thumb_2.png" width=34 height=19 v:shapes="_x0000_i1025" mce_src="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image026_thumb_2.png"></A></SPAN>&nbsp;</P></TD></TR>
<TR style="mso-yfti-irow: 23">
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right><SPAN style="mso-no-proof: yes">nvarchar(max) </SPAN></P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: medium none; PADDING-TOP: 0in; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="MARGIN-BOTTOM: 0pt" class=MsoNormal><SPAN style="LINE-HEIGHT: 110%; FONT-FAMILY: 'Cambria','serif'; FONT-SIZE: 11pt; mso-fareast-font-family: calibri; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-fareast-language: en-us; mso-bidi-language: ar-sa"><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image024_34.png" original-url="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image024_34.png" mce_href="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image024_34.png"><IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=clip_image024 border=0 alt=clip_image024 src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image024_thumb_7.png" original-url="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image024_thumb_7.png" width=12 height=19 v:shapes="_x0000_i1025" mce_src="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image024_thumb_7.png"></A></SPAN>&nbsp;</P></TD></TR>
<TR style="mso-yfti-irow: 24">
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right><SPAN style="mso-no-proof: yes">real </SPAN></P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: medium none; PADDING-TOP: 0in; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="MARGIN-BOTTOM: 0pt" class=MsoNormal>4 </P></TD></TR>
<TR style="mso-yfti-irow: 25">
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right><SPAN style="mso-no-proof: yes">smalldatetime </SPAN></P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: medium none; PADDING-TOP: 0in; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="MARGIN-BOTTOM: 0pt" class=MsoNormal>4 </P></TD></TR>
<TR style="mso-yfti-irow: 26">
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right><SPAN style="mso-no-proof: yes">smallint </SPAN></P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: medium none; PADDING-TOP: 0in; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="MARGIN-BOTTOM: 0pt" class=MsoNormal>2 </P></TD></TR>
<TR style="mso-yfti-irow: 27">
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right><SPAN style="mso-no-proof: yes">smallmoney </SPAN></P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: medium none; PADDING-TOP: 0in; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="MARGIN-BOTTOM: 0pt" class=MsoNormal>4 </P></TD></TR>
<TR style="mso-yfti-irow: 28">
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right><SPAN style="mso-no-proof: yes">sql_variant </SPAN></P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: medium none; PADDING-TOP: 0in; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="MARGIN-BOTTOM: 0pt" class=MsoNormal>8016 </P></TD></TR>
<TR style="mso-yfti-irow: 29">
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right><SPAN style="mso-no-proof: yes">sysname </SPAN></P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: medium none; PADDING-TOP: 0in; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="MARGIN-BOTTOM: 0pt" class=MsoNormal>256 </P></TD></TR>
<TR style="mso-yfti-irow: 30">
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right><SPAN style="mso-no-proof: yes">text </SPAN></P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: medium none; PADDING-TOP: 0in; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="MARGIN-BOTTOM: 0pt" class=MsoNormal><SPAN style="LINE-HEIGHT: 110%; FONT-FAMILY: 'Cambria','serif'; FONT-SIZE: 11pt; mso-fareast-font-family: calibri; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-fareast-language: en-us; mso-bidi-language: ar-sa"><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image024_36.png" original-url="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image024_36.png" mce_href="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image024_36.png"><IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=clip_image024 border=0 alt=clip_image024 src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image024_thumb_8.png" original-url="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image024_thumb_8.png" width=12 height=19 v:shapes="_x0000_i1025" mce_src="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image024_thumb_8.png"></A></SPAN>&nbsp;</P></TD></TR>
<TR style="mso-yfti-irow: 31">
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right><SPAN style="mso-no-proof: yes">time </SPAN></P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: medium none; PADDING-TOP: 0in; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="MARGIN-BOTTOM: 0pt" class=MsoNormal>5 </P></TD></TR>
<TR style="mso-yfti-irow: 32">
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right><SPAN style="mso-no-proof: yes">timestamp </SPAN></P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: medium none; PADDING-TOP: 0in; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="MARGIN-BOTTOM: 0pt" class=MsoNormal>8 </P></TD></TR>
<TR style="mso-yfti-irow: 33">
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right><SPAN style="mso-no-proof: yes">tinyint </SPAN></P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: medium none; PADDING-TOP: 0in; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="MARGIN-BOTTOM: 0pt" class=MsoNormal>1 </P></TD></TR>
<TR style="mso-yfti-irow: 34">
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right><SPAN style="mso-no-proof: yes">uniqueidentifier </SPAN></P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: medium none; PADDING-TOP: 0in; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="MARGIN-BOTTOM: 0pt" class=MsoNormal>16 </P></TD></TR>
<TR style="mso-yfti-irow: 35">
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right><SPAN style="mso-no-proof: yes">varbinary </SPAN></P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: medium none; PADDING-TOP: 0in; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="MARGIN-BOTTOM: 0pt" class=MsoNormal><SPAN style="LINE-HEIGHT: 110%; FONT-FAMILY: 'Cambria','serif'; FONT-SIZE: 11pt; mso-fareast-font-family: calibri; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-fareast-language: en-us; mso-bidi-language: ar-sa"><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image008_22.png" original-url="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image008_22.png" mce_href="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image008_22.png"><IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=clip_image008 border=0 alt=clip_image008 src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image008_thumb_5.png" original-url="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image008_thumb_5.png" width=9 height=19 v:shapes="_x0000_i1025" mce_src="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image008_thumb_5.png"></A></SPAN>&nbsp;</P></TD></TR>
<TR style="mso-yfti-irow: 36">
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right><SPAN style="mso-no-proof: yes">varbinary(max) </SPAN></P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: medium none; PADDING-TOP: 0in; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="MARGIN-BOTTOM: 0pt" class=MsoNormal><SPAN style="LINE-HEIGHT: 110%; FONT-FAMILY: 'Cambria','serif'; FONT-SIZE: 11pt; mso-fareast-font-family: calibri; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-fareast-language: en-us; mso-bidi-language: ar-sa"><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image024_38.png" original-url="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image024_38.png" mce_href="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image024_38.png"><IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=clip_image024 border=0 alt=clip_image024 src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image024_thumb_9.png" original-url="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image024_thumb_9.png" width=12 height=19 v:shapes="_x0000_i1025" mce_src="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image024_thumb_9.png"></A></SPAN>&nbsp;</P></TD></TR>
<TR style="mso-yfti-irow: 37">
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right><SPAN style="mso-no-proof: yes">varchar </SPAN></P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: medium none; PADDING-TOP: 0in; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="MARGIN-BOTTOM: 0pt" class=MsoNormal><SPAN style="LINE-HEIGHT: 110%; FONT-FAMILY: 'Cambria','serif'; FONT-SIZE: 11pt; mso-fareast-font-family: calibri; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-fareast-language: en-us; mso-bidi-language: ar-sa"><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image008_24.png" original-url="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image008_24.png" mce_href="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image008_24.png"><IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=clip_image008 border=0 alt=clip_image008 src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image008_thumb_6.png" original-url="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image008_thumb_6.png" width=9 height=19 v:shapes="_x0000_i1025" mce_src="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image008_thumb_6.png"></A></SPAN>&nbsp;</P></TD></TR>
<TR style="mso-yfti-irow: 38">
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right><SPAN style="mso-no-proof: yes">xml </SPAN></P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: medium none; PADDING-TOP: 0in; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="MARGIN-BOTTOM: 0pt" class=MsoNormal><SPAN style="LINE-HEIGHT: 110%; FONT-FAMILY: 'Cambria','serif'; FONT-SIZE: 11pt; mso-fareast-font-family: calibri; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-fareast-language: en-us; mso-bidi-language: ar-sa"><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image024_40.png" original-url="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image024_40.png" mce_href="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image024_40.png"><IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=clip_image024 border=0 alt=clip_image024 src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image024_thumb_10.png" original-url="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image024_thumb_10.png" width=12 height=19 v:shapes="_x0000_i1025" mce_src="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image024_thumb_10.png"></A></SPAN>&nbsp;</P></TD></TR>
<TR style="mso-yfti-irow: 39">
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right><SPAN style="mso-no-proof: yes">CLR type </SPAN></P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: medium none; PADDING-TOP: 0in; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="MARGIN-BOTTOM: 0pt" class=MsoNormal>? </P></TD></TR>
<TR style="mso-yfti-irow: 40">
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right><SPAN style="mso-no-proof: yes">variable size columns (n) </SPAN></P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: medium none; PADDING-TOP: 0in; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: left; MARGIN-BOTTOM: 0pt" class=MsoNormal align=left><SPAN style="POSITION: relative; LINE-HEIGHT: 110%; FONT-FAMILY: 'Cambria','serif'; FONT-SIZE: 11pt; TOP: 4.5pt; mso-fareast-font-family: calibri; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-fareast-language: en-us; mso-bidi-language: ar-sa; mso-text-raise: -4.5pt"><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image028_4.png" original-url="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image028_4.png" mce_href="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image028_4.png"><IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=clip_image028 border=0 alt=clip_image028 src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image028_thumb_1.png" original-url="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image028_thumb_1.png" width=72 height=19 v:shapes="_x0000_i1025" mce_src="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image028_thumb_1.png"></A></SPAN><SPAN style="FONT-FAMILY: 'Times New Roman','serif'"> </SPAN>(0 if n = 0) </P></TD></TR>
<TR style="mso-yfti-irow: 41">
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right><SPAN style="mso-no-proof: yes">nullable columns (n) </SPAN></P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: medium none; PADDING-TOP: 0in; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: left; MARGIN-BOTTOM: 0pt" class=MsoNormal align=left><SPAN style="POSITION: relative; LINE-HEIGHT: 110%; FONT-FAMILY: 'Cambria','serif'; FONT-SIZE: 11pt; TOP: 4.5pt; mso-fareast-font-family: calibri; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-fareast-language: en-us; mso-bidi-language: ar-sa; mso-text-raise: -4.5pt"><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image030_4.png" original-url="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image030_4.png" mce_href="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image030_4.png"><IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=clip_image030 border=0 alt=clip_image030 src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image030_thumb_1.png" original-url="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image030_thumb_1.png" width=60 height=19 v:shapes="_x0000_i1025" mce_src="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image030_thumb_1.png"></A></SPAN><SPAN style="FONT-FAMILY: 'Times New Roman','serif'"> </SPAN>(0 if n = 0) </P></TD></TR>
<TR style="mso-yfti-irow: 42">
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right><SPAN style="mso-no-proof: yes">clustered overhead </SPAN></P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: medium none; PADDING-TOP: 0in; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: left; MARGIN-BOTTOM: 0pt" class=MsoNormal align=left>4 </P></TD></TR>
<TR style="mso-yfti-irow: 43; mso-yfti-lastrow: yes">
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right><SPAN style="mso-no-proof: yes">nonclustered overhead </SPAN></P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: medium none; PADDING-TOP: 0in; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: left; MARGIN-BOTTOM: 0pt" class=MsoNormal align=left>7 </P></TD></TR></TBODY></TABLE></DIV>
<H2>Using hash indexes to enforce uniqueness constraints </H2>
<P class=MsoNoSpacing>If the index key will always be 900 bytes or less, then an ordinary uniqueness constraint may be used. If the index key could be greater than 900 bytes, then a uniqueness constraint can be enforced with an after-trigger. To avoid table scans, a hash index can be generated for the columns with the unique constraint. The uniqueness constraint can be enforced with the scheme: </P>
<P class=Codenospacing><SPAN style="COLOR: blue">create</SPAN> <SPAN style="COLOR: blue">table</SPAN> [<I style="mso-bidi-font-style: normal">Schema</I>]<SPAN style="COLOR: gray">.</SPAN>[<I style="mso-bidi-font-style: normal">Table</I>] <BR><SPAN style="COLOR: gray">( <BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp; </SPAN>[Id]<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">int</SPAN> <SPAN style="COLOR: gray">not</SPAN> <SPAN style="COLOR: gray">null</SPAN> <SPAN style="COLOR: blue">constraint</SPAN> [PK_<I style="mso-bidi-font-style: normal">Table</I>] <SPAN style="COLOR: blue">primary</SPAN> <SPAN style="COLOR: blue">key</SPAN><SPAN style="COLOR: gray">, <BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp; </SPAN>…<SPAN style="COLOR: gray">,</SPAN> <BR><SPAN style="mso-spacerun: yes">&nbsp; </SPAN>[<I style="mso-bidi-font-style: normal">Column<SUB>1</SUB></I>] <I style="mso-bidi-font-style: normal"><SPAN style="COLOR: blue">Column<SUB>1</SUB>TypeDeclaration</SPAN></I><SPAN style="COLOR: blue"> not null</SPAN><SPAN style="COLOR: gray">, <BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp; </SPAN>[<I style="mso-bidi-font-style: normal">Column<SUB>2</SUB></I>] <I style="mso-bidi-font-style: normal"><SPAN style="COLOR: blue">Column<SUB>2</SUB>TypeDeclaration</SPAN></I><SPAN style="COLOR: blue"> null</SPAN><SPAN style="COLOR: gray">, <BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp; </SPAN>…<SPAN style="COLOR: gray">,</SPAN> <BR><SPAN style="mso-spacerun: yes">&nbsp; </SPAN>[Internal_Hash_<I style="mso-bidi-font-style: normal">Column<SUB>1</SUB></I>_<I style="mso-bidi-font-style: normal">Column<SUB>2</SUB></I>] <SPAN style="COLOR: blue">as</SPAN> <SPAN style="COLOR: fuchsia">checksum</SPAN><SPAN style="COLOR: gray">(</SPAN>[<I style="mso-bidi-font-style: normal">Column<SUB>1</SUB></I>]<SPAN style="COLOR: gray">,</SPAN> [<I style="mso-bidi-font-style: normal">Column<SUB>2</SUB></I>]<SPAN style="COLOR: gray">)</SPAN> <SPAN style="COLOR: blue">persisted</SPAN> <SPAN style="COLOR: gray">not</SPAN> <SPAN style="COLOR: gray">null <BR>); <BR></SPAN><SPAN style="COLOR: blue">go <BR><BR>create</SPAN> <SPAN style="COLOR: blue">index</SPAN> [Unique_Hash_<I style="mso-bidi-font-style: normal">Table</I>_Column<SUB>1</SUB>_Column<SUB>2</SUB>] <SPAN style="COLOR: blue">on</SPAN> [<I style="mso-bidi-font-style: normal">Schema</I>]<SPAN style="COLOR: gray">.</SPAN>[<I style="mso-bidi-font-style: normal">Table</I>]<SPAN style="COLOR: blue"> </SPAN><SPAN style="COLOR: gray">(</SPAN>[Internal_Hash_<I style="mso-bidi-font-style: normal">Column<SUB>1</SUB></I>_<I style="mso-bidi-font-style: normal">Column<SUB>2</SUB></I>]<SPAN style="COLOR: gray">); <BR></SPAN><SPAN style="COLOR: blue">go <BR><BR>create</SPAN> <SPAN style="COLOR: blue">trigger</SPAN> [ConstraintInsertTrigger_<I style="mso-bidi-font-style: normal">Extent</I>] <SPAN style="COLOR: blue">on</SPAN> [<I style="mso-bidi-font-style: normal">Schema</I>]<SPAN style="COLOR: gray">.</SPAN>[<I style="mso-bidi-font-style: normal">Table</I>] <BR><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">after</SPAN> <SPAN style="COLOR: blue">of</SPAN> <SPAN style="COLOR: blue">insert</SPAN>, <SPAN style="COLOR: blue">update</SPAN> <SPAN style="COLOR: blue">as <BR>begin <BR></SPAN><SPAN style="mso-bidi-font-family: consolas; mso-bidi-font-size: 9.0pt"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">if </SPAN><SPAN style="COLOR: gray">(</SPAN><SPAN style="COLOR: blue">update</SPAN><SPAN style="COLOR: gray">(</SPAN>[</SPAN><I style="mso-bidi-font-style: normal">Column<SUB>1</SUB></I><SPAN style="mso-bidi-font-family: consolas; mso-bidi-font-size: 9.0pt">]<SPAN style="COLOR: gray">)</SPAN> <SPAN style="COLOR: gray">or</SPAN> <SPAN style="COLOR: blue">update</SPAN><SPAN style="COLOR: gray">(</SPAN>[</SPAN><I style="mso-bidi-font-style: normal">Column<SUB>2</SUB></I><SPAN style="mso-bidi-font-family: consolas; mso-bidi-font-size: 9.0pt">]<SPAN style="COLOR: gray">))</SPAN> <SPAN style="COLOR: gray">and <BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN><SPAN style="COLOR: gray">exists</SPAN><SPAN style="COLOR: blue"> </SPAN><SPAN style="COLOR: gray">(</SPAN><SPAN style="COLOR: blue">select</SPAN> <SPAN style="COLOR: gray">* <BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;</SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">from</SPAN> [<I style="mso-bidi-font-style: normal">Schema</I>]<SPAN style="COLOR: gray">.</SPAN>[</SPAN><I style="mso-bidi-font-style: normal">Table</I><SPAN style="mso-bidi-font-family: consolas; mso-bidi-font-size: 9.0pt">] <SPAN style="COLOR: blue">as</SPAN> T <BR><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: gray">inner</SPAN> <SPAN style="COLOR: gray">join</SPAN> inserted <SPAN style="COLOR: blue">as</SPAN> I <SPAN style="COLOR: blue">on</SPAN> I<SPAN style="COLOR: gray">.</SPAN>[</SPAN>Internal_Hash_<I style="mso-bidi-font-style: normal">Column<SUB>1</SUB></I>_<I style="mso-bidi-font-style: normal">Column<SUB>2</SUB></I><SPAN style="mso-bidi-font-family: consolas; mso-bidi-font-size: 9.0pt">] <SPAN style="COLOR: gray">=</SPAN> T<SPAN style="COLOR: gray">.</SPAN> [</SPAN>Internal_Hash_<I style="mso-bidi-font-style: normal">Column<SUB>1</SUB></I>_<I style="mso-bidi-font-style: normal">Column<SUB>2</SUB></I><SPAN style="mso-bidi-font-family: consolas; mso-bidi-font-size: 9.0pt">] <SPAN style="COLOR: gray">and <BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp; </SPAN>I<SPAN style="COLOR: gray">.</SPAN>[</SPAN><I style="mso-bidi-font-style: normal">Column<SUB>1</SUB></I><SPAN style="mso-bidi-font-family: consolas; mso-bidi-font-size: 9.0pt">] <SPAN style="COLOR: gray">=</SPAN> T<SPAN style="COLOR: gray">.</SPAN>[</SPAN><I style="mso-bidi-font-style: normal">Column<SUB>1</SUB></I><SPAN style="mso-bidi-font-family: consolas; mso-bidi-font-size: 9.0pt">] <SPAN style="COLOR: gray">and <BR></SPAN><SPAN style="COLOR: blue"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp; </SPAN></SPAN><SPAN style="COLOR: gray">(</SPAN>I<SPAN style="COLOR: gray">.</SPAN>[</SPAN><I style="mso-bidi-font-style: normal">Column<SUB>2</SUB></I><SPAN style="mso-bidi-font-family: consolas; mso-bidi-font-size: 9.0pt">] <SPAN style="COLOR: gray">=</SPAN> T<SPAN style="COLOR: gray">.</SPAN>[</SPAN><I style="mso-bidi-font-style: normal">Column<SUB>2</SUB></I><SPAN style="mso-bidi-font-family: consolas; mso-bidi-font-size: 9.0pt">] <SPAN style="COLOR: gray">or</SPAN><SPAN style="COLOR: blue"> </SPAN><SPAN style="COLOR: gray">(</SPAN>I<SPAN style="COLOR: gray">.</SPAN>[</SPAN><I style="mso-bidi-font-style: normal"><SPAN style="mso-bidi-font-size: 9.0pt">Column<SUB>2</SUB></SPAN></I><SPAN style="mso-bidi-font-family: consolas; mso-bidi-font-size: 9.0pt">] <SPAN style="COLOR: gray">is</SPAN> <SPAN style="COLOR: gray">null</SPAN> <SPAN style="COLOR: gray">and</SPAN> T<SPAN style="COLOR: gray">.</SPAN>[</SPAN><I style="mso-bidi-font-style: normal"><SPAN style="mso-bidi-font-size: 9.0pt">Column<SUB>2</SUB></SPAN></I><SPAN style="mso-bidi-font-family: consolas; mso-bidi-font-size: 9.0pt">] <SPAN style="COLOR: gray">is</SPAN> <SPAN style="COLOR: gray">null)) <BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">group</SPAN> <SPAN style="COLOR: blue">by</SPAN> I<SPAN style="COLOR: gray">.</SPAN>[</SPAN><SPAN style="mso-bidi-font-size: 9.0pt">Internal_Hash_<I style="mso-bidi-font-style: normal">Column<SUB>1</SUB></I>_<I style="mso-bidi-font-style: normal">Column<SUB>2</SUB></I></SPAN><SPAN style="mso-bidi-font-family: consolas; mso-bidi-font-size: 9.0pt">]<SPAN style="COLOR: gray">,</SPAN> I<SPAN style="COLOR: gray">.</SPAN>[</SPAN><I style="mso-bidi-font-style: normal"><SPAN style="mso-bidi-font-size: 9.0pt">Column<SUB>1</SUB></SPAN></I><SPAN style="mso-bidi-font-family: consolas; mso-bidi-font-size: 9.0pt">]<SPAN style="COLOR: gray">,</SPAN> I<SPAN style="COLOR: gray">.</SPAN>[</SPAN><I style="mso-bidi-font-style: normal"><SPAN style="mso-bidi-font-size: 9.0pt">Column<SUB>2</SUB></SPAN></I><SPAN style="mso-bidi-font-family: consolas; mso-bidi-font-size: 9.0pt">] <BR><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">having</SPAN> <SPAN style="COLOR: fuchsia">count</SPAN><SPAN style="COLOR: gray">(*)</SPAN> <SPAN style="COLOR: gray">&gt;</SPAN> 1<SPAN style="COLOR: gray">) <BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp;</SPAN></SPAN><SPAN style="mso-bidi-font-size: 9.0pt"><SPAN style="mso-spacerun: yes">&nbsp;</SPAN><SPAN style="COLOR: blue">begin <BR></SPAN></SPAN><SPAN style="mso-bidi-font-family: consolas; mso-bidi-font-size: 9.0pt"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">if</SPAN> <SPAN style="COLOR: fuchsia">@@trancount</SPAN> <SPAN style="COLOR: gray">&gt;</SPAN> 0 <BR><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">begin <BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">rollback</SPAN> <SPAN style="COLOR: blue">transaction</SPAN><SPAN style="COLOR: gray">; <BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp;</SPAN><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;</SPAN><SPAN style="COLOR: blue">end</SPAN><SPAN style="COLOR: gray">; <BR><BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">raiserror</SPAN><SPAN style="COLOR: gray">(</SPAN><SPAN style="COLOR: red">N'Error: Values in the columns [<I style="mso-bidi-font-style: normal">Schema</I>].[<I style="mso-bidi-font-style: normal">Table</I>] ([<I style="mso-bidi-font-style: normal">Column<SUB>1</SUB></I>], [<I style="mso-bidi-font-style: normal">Column<SUB>2</SUB></I>]) must be unique.'</SPAN><SPAN style="COLOR: gray">,</SPAN> 16<SPAN style="COLOR: gray">,</SPAN> 0<SPAN style="COLOR: gray">);</SPAN></SPAN><SPAN style="COLOR: gray; mso-bidi-font-size: 9.0pt"> <BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">end</SPAN><SPAN style="COLOR: gray">; <BR></SPAN><SPAN style="COLOR: blue">end</SPAN><SPAN style="COLOR: gray">; <BR></SPAN><SPAN style="COLOR: blue">go </SPAN>
<P class=MsoNormal>Essentially, the strategy is to store an indexed hash of the columns in the uniqueness constraint. The after trigger makes sure there are no duplicates, by searching for rows that both hash to the same value as one of the inserted rows and match on the constrained columns. Using hashes avoids scanning the entire table for matches and has good space efficiency. The above scheme shows how to handle multiple columns and both nullable and non-nullable columns. </P>
<P mce_keep="true">The reason to use checksum and neither hashbytes nor binary_checksum is that checksum respects collation. For example, </P>
<P style="MARGIN: 0in 0in 0pt 0.5in" class=MsoNormal><SPAN style="LINE-HEIGHT: 110%; FONT-FAMILY: consolas; FONT-SIZE: 9pt">checksum(N'X')</SPAN> = <SPAN style="LINE-HEIGHT: 110%; FONT-FAMILY: consolas; FONT-SIZE: 9pt">checksum(N'x') </SPAN>
<P mce_keep="true">but </P>
<P style="MARGIN: 0in 0in 0pt 0.5in" class=MsoNormal><SPAN style="LINE-HEIGHT: 110%; FONT-FAMILY: consolas; FONT-SIZE: 9pt">binary_checksum(N'X')</SPAN> ≠ <SPAN style="LINE-HEIGHT: 110%; FONT-FAMILY: consolas; FONT-SIZE: 9pt">binary_checksum(N'x')</SPAN>. </P>
<P mce_keep="true">However, hashbytes and binary_checksum are suitable hashing functions for non-text columns. Also if the constrained columns are unlikely to contain common prefixes, a prefix of the columns (e.g. <SPAN style="LINE-HEIGHT: 110%; FONT-FAMILY: consolas; FONT-SIZE: 10pt">left([Column], 10)</SPAN>) may be a very good hashing function. </P>
<H2>Using a uniqueness constraint on a hashed column to enforce uniqueness constraints </H2>
<P style="MARGIN-BOTTOM: 0pt" class=MsoNormal>A common alternative strategy is to put a unique constraint over a persisted column defined using hashbytes. The idea is that the chance of a collision for, say, a SHA1 hash is so low that other bugs or hardware failures are much more likely to cause a failure. However, because of the <A href="https://skepticwiki.org/index.php/Birthday_Paradox" mce_href="https://skepticwiki.org/index.php/Birthday_Paradox">Birthday Fallacy/Paradox</A> people often underestimate the chance of a collision happening. If a hashing function is perfect then the chance of there being a collision among <I style="mso-bidi-font-style: normal">n</I> randomly chosen values in a <I style="mso-bidi-font-style: normal">b</I>-bit hash is approximately: </P>
<P style="MARGIN-BOTTOM: 0pt" class=MsoNormal><SPAN style="LINE-HEIGHT: 110%; FONT-FAMILY: 'Cambria','serif'; FONT-SIZE: 11pt; mso-fareast-font-family: calibri; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-fareast-language: en-us; mso-bidi-language: ar-sa"><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image032_4.png" original-url="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image032_4.png" mce_href="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image032_4.png"><IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: block; FLOAT: none; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; MARGIN-LEFT: auto; BORDER-LEFT-WIDTH: 0px; MARGIN-RIGHT: auto" title=clip_image032 border=0 alt=clip_image032 src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image032_thumb_1.png" original-url="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image032_thumb_1.png" width=79 height=30 v:shapes="_x0000_i1025" mce_src="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image032_thumb_1.png"></A></SPAN><I style="mso-bidi-font-style: normal"><SPAN style="FONT-FAMILY: 'Cambria Math','serif'; mso-fareast-font-family: 'MS Mincho'; mso-bidi-font-family: 'MS Mincho'">&nbsp;</SPAN></I>In general, a collision is highly likely in a sample of size 
<P style="MARGIN-BOTTOM: 0pt" class=MsoNormal><SPAN style="LINE-HEIGHT: 110%; FONT-FAMILY: 'Cambria','serif'; FONT-SIZE: 11pt; mso-fareast-font-family: calibri; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-fareast-language: en-us; mso-bidi-language: ar-sa"><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image034_4.png" original-url="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image034_4.png" mce_href="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image034_4.png"><IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: block; FLOAT: none; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; MARGIN-LEFT: auto; BORDER-LEFT-WIDTH: 0px; MARGIN-RIGHT: auto" title=clip_image034 border=0 alt=clip_image034 src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image034_thumb_1.png" original-url="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image034_thumb_1.png" width=27 height=20 v:shapes="_x0000_i1025" mce_src="https://blogs.msdn.com/blogfiles/anthonybloesch/WindowsLiveWriter/97b014b048dd_88E1/clip_image034_thumb_1.png"></A></SPAN> </P>
<P mce_keep="true">Thus for, say, the 160 bit SHA1 hash the chance of a collision in even a trillion random rows seems very low. However, there are some flaws in this argument: </P>
<P mce_keep="true"><SPAN style="FONT-FAMILY: symbol; mso-fareast-font-family: symbol; mso-bidi-font-family: symbol"><SPAN style="mso-list: ignore">·<SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN></SPAN>Cryptographic hashing functions are poorly understood but there are strong indications that MD5 and SHA1 are weaker than perfect hashing functions. </P>
<P mce_keep="true"><SPAN style="FONT-FAMILY: symbol; mso-fareast-font-family: symbol; mso-bidi-font-family: symbol"><SPAN style="mso-list: ignore">·<SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN></SPAN>For a given value, it is often feasible to find another value that hashes to the same hash (i.e. a hash collision). Thus if an application could be compromised by a hash collision and an adversary has some control over the values the application uses then this strategy is unsuitable. </P>
<P mce_keep="true"><SPAN style="FONT-FAMILY: symbol; mso-fareast-font-family: symbol; mso-bidi-font-family: symbol"><SPAN style="mso-list: ignore">·<SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN></SPAN>Cryptographic hash functions do not respect collations. Thus, two strings that are equal like ‘X’ and ‘x’ (in a case insensitive collation) may hash to different hashes. </P>
<P mce_keep="true"><SPAN style="FONT-FAMILY: symbol; mso-fareast-font-family: symbol; mso-bidi-font-family: symbol"><SPAN style="mso-list: ignore">·<SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN></SPAN>The input to the hashing function is usually not random. </P>
<H2>Relative performance of the hash index approach for columns under 900 bytes </H2>
<P class=MsoNormal>It seems likely that the hash index approach is more efficient than the unique index based approach at enforcing uniqueness constraints. Table <SPAN style="mso-no-proof: yes">2</SPAN> and Table <SPAN style="mso-no-proof: yes">3</SPAN> show the average time to insert and delete 1 000 and 100 000 rows for various sized strings with a uniqueness constraint. The SQL Server unique constraint and the hash index approach are compared for both the no prefix and the 20 byte (10 Unicode character) common prefix cases. From this analysis, it is clear that for column sets under 900 bytes the hash index approach is unlikely to perform better than a traditional unique index based approach. The test was carried out on a dedicated workstation with an Intel Pentium D 3.00GHz processor and 4 GB of RAM. The test script is attached to this blog entry. </P>
<BLOCKQUOTE>
<P class=MsoCaption><A title=_Ref246513463 name=_Ref246513463></A>Table <SPAN style="mso-bookmark: _ref246513463"><SPAN style="mso-no-proof: yes">2</SPAN></SPAN><SPAN style="mso-bookmark: _ref246513463"></SPAN>: The average time, in seconds, to insert and delete 1 000 rows with a Unicode string with a uniqueness constraint. Both the unique and hash index approaches to uniqueness constraint enforcement are tabulated. Both random strings and strings with a fixed 20 byte (10 Unicode character) prefix are tabulated. The first time in each pair, is the time to insert 1 000 rows at once. The second time in each pair, is the time to insert 1 000 rows separately (i.e. 1 at a time). </P></BLOCKQUOTE>
<DIV align=center>
<TABLE style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; BORDER-COLLAPSE: collapse; BORDER-TOP: medium none; BORDER-RIGHT: medium none; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt" class=MsoTableGrid border=0 cellSpacing=0 cellPadding=0 class="MsoTableGrid">
<TBODY>
<TR style="mso-yfti-irow: 0; mso-yfti-firstrow: yes">
<TD style="PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; PADDING-TOP: 0in" vAlign=top>
<P style="MARGIN-BOTTOM: 0pt" class=MsoNormal mce_keep="true">&nbsp;</P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: windowtext 1pt solid; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" vAlign=top colSpan=4>
<P style="TEXT-ALIGN: center; MARGIN-BOTTOM: 0pt" class=MsoNormal align=center><B style="mso-bidi-font-weight: normal">Unique index </B></P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: medium none; PADDING-TOP: 0in; mso-border-left-alt: solid windowtext .5pt" vAlign=top colSpan=4>
<P style="TEXT-ALIGN: center; MARGIN-BOTTOM: 0pt" class=MsoNormal align=center><B style="mso-bidi-font-weight: normal">Hash index </B></P></TD></TR>
<TR style="mso-yfti-irow: 1">
<TD style="BORDER-BOTTOM: windowtext 1pt solid; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" vAlign=top>
<P style="MARGIN-BOTTOM: 0pt" class=MsoNormal><B style="mso-bidi-font-weight: normal">Length</B> </P></TD>
<TD style="BORDER-BOTTOM: windowtext 1pt solid; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" vAlign=top colSpan=2>
<P style="MARGIN-BOTTOM: 0pt" class=MsoNormal><B style="mso-bidi-font-weight: normal">No prefix </B></P></TD>
<TD style="BORDER-BOTTOM: windowtext 1pt solid; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" vAlign=top colSpan=2>
<P style="MARGIN-BOTTOM: 0pt" class=MsoNormal><B style="mso-bidi-font-weight: normal">With prefix </B></P></TD>
<TD style="BORDER-BOTTOM: windowtext 1pt solid; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" vAlign=top colSpan=2>
<P style="MARGIN-BOTTOM: 0pt" class=MsoNormal><B style="mso-bidi-font-weight: normal">No prefix </B></P></TD>
<TD style="BORDER-BOTTOM: windowtext 1pt solid; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: medium none; PADDING-TOP: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" vAlign=top colSpan=2>
<P style="MARGIN-BOTTOM: 0pt" class=MsoNormal><B style="mso-bidi-font-weight: normal">With prefix </B></P></TD></TR>
<TR style="mso-yfti-irow: 2">
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" vAlign=top>
<P style="MARGIN-BOTTOM: 0pt" class=MsoNormal><B style="mso-bidi-font-weight: normal">50 </B></P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right>0.10 </P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right>0.43 </P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right>0.11 </P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right>0.46 </P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right>0.12 </P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right>0.59 </P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right>0.12 </P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: medium none; PADDING-TOP: 0in; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right>0.59 </P></TD></TR>
<TR style="mso-yfti-irow: 3">
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt" vAlign=top>
<P style="MARGIN-BOTTOM: 0pt" class=MsoNormal><B style="mso-bidi-font-weight: normal">100 </B></P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right>0.18 </P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right>0.45 </P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right>0.18 </P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right>0.44 </P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right>0.14 </P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right>0.58 </P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right>0.14 </P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: medium none; PADDING-TOP: 0in; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right>0.57 </P></TD></TR>
<TR style="mso-yfti-irow: 4">
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt" vAlign=top>
<P style="MARGIN-BOTTOM: 0pt" class=MsoNormal><B style="mso-bidi-font-weight: normal">200 </B></P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right>0.26 </P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right>0.56 </P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right>0.26 </P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right>0.54 </P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right>0.28 </P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right>0.62 </P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right>0.24 </P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: medium none; PADDING-TOP: 0in; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right>0.60 </P></TD></TR>
<TR style="mso-yfti-irow: 5; mso-yfti-lastrow: yes">
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt" vAlign=top>
<P style="MARGIN-BOTTOM: 0pt" class=MsoNormal><B style="mso-bidi-font-weight: normal">400 </B></P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right>0.37 </P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right>0.62 </P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right>0.39 </P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right>0.66 </P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right>0.31 </P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right>0.65 </P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right>0.42 </P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: medium none; PADDING-TOP: 0in; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right>0.70 </P></TD></TR></TBODY></TABLE></DIV>
<BLOCKQUOTE>
<P class=MsoCaption><A title=_Ref246513469 name=_Ref246513469></A>Table <SPAN style="mso-bookmark: _ref246513469"><SPAN style="mso-no-proof: yes">3</SPAN></SPAN><SPAN style="mso-bookmark: _ref246513469"></SPAN>: The average time, in seconds, to insert and delete 100 000 rows with a Unicode string with a uniqueness constraint. Both the unique and hash index approaches to uniqueness constraint enforcement are tabulated. Both random strings and strings with a fixed 20 byte (10 Unicode character) prefix are tabulated. The first time in each pair, is the time to insert 100 000 rows at once. The second time in each pair, is the time to insert 100 000 rows separately (i.e. 1 at a time). </P></BLOCKQUOTE>
<DIV align=center>
<TABLE style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; BORDER-COLLAPSE: collapse; BORDER-TOP: medium none; BORDER-RIGHT: medium none; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt" class=MsoTableGrid border=0 cellSpacing=0 cellPadding=0 class="MsoTableGrid">
<TBODY>
<TR style="mso-yfti-irow: 0; mso-yfti-firstrow: yes">
<TD style="PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; PADDING-TOP: 0in" vAlign=top>
<P style="MARGIN-BOTTOM: 0pt" class=MsoNormal mce_keep="true">&nbsp;</P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: windowtext 1pt solid; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" vAlign=top colSpan=4>
<P style="TEXT-ALIGN: center; MARGIN-BOTTOM: 0pt" class=MsoNormal align=center><B style="mso-bidi-font-weight: normal">Unique index </B></P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: medium none; PADDING-TOP: 0in; mso-border-left-alt: solid windowtext .5pt" vAlign=top colSpan=4>
<P style="TEXT-ALIGN: center; MARGIN-BOTTOM: 0pt" class=MsoNormal align=center><B style="mso-bidi-font-weight: normal">Hash index </B></P></TD></TR>
<TR style="mso-yfti-irow: 1">
<TD style="BORDER-BOTTOM: windowtext 1pt solid; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" vAlign=top>
<P style="MARGIN-BOTTOM: 0pt" class=MsoNormal><B style="mso-bidi-font-weight: normal">Length</B> </P></TD>
<TD style="BORDER-BOTTOM: windowtext 1pt solid; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" vAlign=top colSpan=2>
<P style="MARGIN-BOTTOM: 0pt" class=MsoNormal><B style="mso-bidi-font-weight: normal">No prefix </B></P></TD>
<TD style="BORDER-BOTTOM: windowtext 1pt solid; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" vAlign=top colSpan=2>
<P style="MARGIN-BOTTOM: 0pt" class=MsoNormal><B style="mso-bidi-font-weight: normal">With prefix </B></P></TD>
<TD style="BORDER-BOTTOM: windowtext 1pt solid; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" vAlign=top colSpan=2>
<P style="MARGIN-BOTTOM: 0pt" class=MsoNormal><B style="mso-bidi-font-weight: normal">No prefix </B></P></TD>
<TD style="BORDER-BOTTOM: windowtext 1pt solid; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: medium none; PADDING-TOP: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" vAlign=top colSpan=2>
<P style="MARGIN-BOTTOM: 0pt" class=MsoNormal><B style="mso-bidi-font-weight: normal">With prefix </B></P></TD></TR>
<TR style="mso-yfti-irow: 2">
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" vAlign=top>
<P style="MARGIN-BOTTOM: 0pt" class=MsoNormal><B style="mso-bidi-font-weight: normal">50 </B></P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right>6.71 </P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right>36.22 </P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right>6.92 </P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right>35.05 </P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right>20.82 </P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right>52.60 </P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right>20.54 </P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: medium none; PADDING-TOP: 0in; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right>60.33 </P></TD></TR>
<TR style="mso-yfti-irow: 3">
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt" vAlign=top>
<P style="MARGIN-BOTTOM: 0pt" class=MsoNormal><B style="mso-bidi-font-weight: normal">100 </B></P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right>7.09 </P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right>37.36 </P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right>7.33 </P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right>37.02 </P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right>39.92 </P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right>57.03 </P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right>36.14 </P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: medium none; PADDING-TOP: 0in; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right>57.46 </P></TD></TR>
<TR style="mso-yfti-irow: 4">
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt" vAlign=top>
<P style="MARGIN-BOTTOM: 0pt" class=MsoNormal><B style="mso-bidi-font-weight: normal">200 </B></P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right>16.38 </P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right>43.13 </P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right>15.01 </P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right>44.09 </P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right>65.81 </P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right>59.12 </P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right>62.35 </P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: medium none; PADDING-TOP: 0in; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right>59.55 </P></TD></TR>
<TR style="mso-yfti-irow: 5; mso-yfti-lastrow: yes">
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt" vAlign=top>
<P style="MARGIN-BOTTOM: 0pt" class=MsoNormal><B style="mso-bidi-font-weight: normal">400 </B></P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right>33.59 </P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right>55.07 </P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right>24.99 </P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right>56.63 </P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right>149.95 </P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right>70.06 </P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right>151.21 </P></TD>
<TD style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; BORDER-RIGHT: medium none; PADDING-TOP: 0in; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; MARGIN-BOTTOM: 0pt" class=MsoNormal align=right>71.07 </P></TD></TR></TBODY></TABLE></DIV>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Components.PostAttachments/00/09/92/74/22/Large%20uniqueness%20constraints.docx" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-components-postattachments/00-09-92-74-22/Large-uniqueness-constraints.docx">Large uniqueness constraints.docx</a></p>]]></content:encoded>
    </item>
    <item>
      <title>SQL Server Modeling Services announcement</title>
      <link>https://docs.microsoft.com/archive/blogs/anthonybloesch/sql-server-modeling-services-announcement</link>
      <pubDate>Thu, 19 Nov 2009 09:28:00 GMT</pubDate>
      <dc:creator><![CDATA[Anthony Bloesch]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/anthonybloesch/2009/11/19/sql-server-modeling-services-announcement/</guid>
      <description><![CDATA[The code name “Oslo” repository now has the official name “SQL Server Modeling Services”. SQL Server...]]></description>
      <content:encoded><![CDATA[<P style="MARGIN: 0in 0in 10pt" class=MsoNormal><FONT size=3 face=Calibri>The code name “Oslo” repository now has the official name “SQL Server Modeling Services”. SQL Server Modeling Services will be a SQL Server workload like SQL Server Reporting Services. Details will be announced at the PDC where the most relevant session is </FONT><A href="https://microsoftpdc.com/Sessions/SVR19"><SPAN style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"><FONT color=#0000ff size=3 face=Calibri>https://microsoftpdc.com/Sessions/SVR19</FONT></SPAN></A><FONT size=3 face=Calibri>. You can also read about it online at </FONT><A href="https://msdn.microsoft.com/en-us/library/dd129586(VS.85).aspx"><FONT size=3 face=Calibri>https://msdn.microsoft.com/en-us/library/dd129586(VS.85).aspx</FONT></A><FONT size=3><FONT face=Calibri>.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></FONT></FONT></P>
<P style="MARGIN: 0in 0in 10pt" class=MsoNormal><FONT size=3><FONT face=Calibri>In Microsoft, like most organizations, it is hard to get things done when you are in different organizational units and on different schedules. This move makes the repository team firmly part of the SQL Server team and on the same schedule. Thus this change will make alignment and deep integration of the repository with rest of the SQL Server platform easier. Also it provides a simple setup experience and much simpler licensing model for customers. Already, there are many planned changes for the next version of SQL Server that will make for a much stronger metadata store and overall platform.<o:p></o:p></FONT></FONT></P>]]></content:encoded>
    </item>
    <item>
      <title>Paging SQL Server result sets</title>
      <link>https://docs.microsoft.com/archive/blogs/anthonybloesch/paging-sql-server-result-sets</link>
      <pubDate>Mon, 09 Nov 2009 12:21:00 GMT</pubDate>
      <dc:creator><![CDATA[Anthony Bloesch]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/anthonybloesch/2009/11/09/paging-sql-server-result-sets/</guid>
      <description><![CDATA[Paging through result sets is an approach for reducing the network and client resources used to...]]></description>
      <content:encoded><![CDATA[<P style="MARGIN: 0in 0in 10pt" class=MsoNormal><FONT size=3><FONT face=Calibri>Paging through result sets is an approach for reducing the network and client resources used to display large result sets. Essentially, the approach is to load only a page (e.g. 100 rows) of data at a time. It is likely that a user will only want to see a page of data. If they want to see more data then the next page is retrieved etc. Because the entire result set is probably not retrieved and does not need to be stored on the client the network and client resource demands will be lower. Ideally, latency for showing the first rows of data should also be lower since only a subset of data is needed.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></FONT></FONT></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><FONT size=3><FONT face=Calibri>The most commonly advocated SQL Server paging approach is based on the <I style="mso-bidi-font-style: normal">row_number </I>ranking function.<o:p></o:p></FONT></FONT></P>
<P style="MARGIN: 0in 0in 0pt 0.5in" class=MsoNormal><SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: Consolas; COLOR: blue; FONT-SIZE: 9pt; mso-no-proof: yes">with</SPAN><SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: Consolas; FONT-SIZE: 9pt; mso-no-proof: yes"> NumberedResult <SPAN style="COLOR: blue">as<BR></SPAN><SPAN style="COLOR: gray">(<BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">select</SPAN> <SPAN style="COLOR: fuchsia">row_number</SPAN><SPAN style="COLOR: gray">()</SPAN> <SPAN style="COLOR: blue">over </SPAN><SPAN style="COLOR: gray">(</SPAN><SPAN style="COLOR: blue">order</SPAN> <SPAN style="COLOR: blue">by</SPAN> M<SPAN style="COLOR: gray">.</SPAN>[Id]<SPAN style="COLOR: gray">)</SPAN> <SPAN style="COLOR: blue">as</SPAN> [Row]<SPAN style="COLOR: gray">,</SPAN> M<SPAN style="COLOR: gray">.</SPAN>[Id]<SPAN style="COLOR: gray">,</SPAN> M<SPAN style="COLOR: gray">.</SPAN>[Name]<BR><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">from</SPAN> [System_Runtime]<SPAN style="COLOR: gray">.</SPAN>[Methods] <SPAN style="COLOR: blue">as</SPAN> M<BR><SPAN style="COLOR: gray">)<BR></SPAN><SPAN style="COLOR: blue">select</SPAN> NR<SPAN style="COLOR: gray">.</SPAN>[Id]<SPAN style="COLOR: gray">,</SPAN> NR<SPAN style="COLOR: gray">.</SPAN>[Name]<BR><SPAN style="COLOR: blue">from</SPAN> NumberedResult <SPAN style="COLOR: blue">as</SPAN> NR<BR><SPAN style="COLOR: blue">where</SPAN> NR<SPAN style="COLOR: gray">.</SPAN>[Row] <SPAN style="COLOR: gray">between</SPAN> @startRow <SPAN style="COLOR: gray">and</SPAN> @stopRow<SPAN style="COLOR: gray">;<o:p></o:p></SPAN></SPAN></P>
<P style="MARGIN: 0in 0in 10pt" class=MsoNormal><FONT size=3><FONT face=Calibri>This works by associating a row number with each row and fetching blocks of row numbers. For this to work correctly there must be a fixed row order defined by the <I style="mso-bidi-font-style: normal">over</I> expression and the result set must be unchanging. Otherwise each call to the query may return results in a different order or even different results destroying the illusion of paging through a point in time result set.<o:p></o:p></FONT></FONT></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><FONT size=3><FONT face=Calibri>A generally better approach is to use <I style="mso-bidi-font-style: normal">top</I> to retrieve a page of data.<o:p></o:p></FONT></FONT></P>
<P style="MARGIN: 0in 0in 0pt 0.5in" class=MsoNormal><SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: Consolas; COLOR: blue; FONT-SIZE: 9pt; mso-no-proof: yes">select</SPAN><SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: Consolas; FONT-SIZE: 9pt; mso-no-proof: yes"> <SPAN style="COLOR: blue">top</SPAN><SPAN style="COLOR: gray">(</SPAN>@pageSize<SPAN style="COLOR: gray">)</SPAN> M<SPAN style="COLOR: gray">.</SPAN>[Id]<SPAN style="COLOR: gray">,</SPAN> M<SPAN style="COLOR: gray">.</SPAN>[Name]<BR><SPAN style="COLOR: blue">from</SPAN> [System_Runtime]<SPAN style="COLOR: gray">.</SPAN>[Methods] <SPAN style="COLOR: blue">as</SPAN> M<BR><SPAN style="COLOR: blue">where</SPAN> M<SPAN style="COLOR: gray">.</SPAN>[Id] <SPAN style="COLOR: gray">&gt;</SPAN> @lastId<BR><SPAN style="COLOR: blue">order</SPAN> <SPAN style="COLOR: blue">by</SPAN> M<SPAN style="COLOR: gray">.</SPAN>[Id]<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 10pt" class=MsoNormal><FONT face=Calibri><FONT size=3>As before, for this to work correctly there must be a fixed row order defined by the <I style="mso-bidi-font-style: normal">order by</I> clause and the result set must be unchanging. The reason this will usually work better is that if the order by clause is covered by an index then the data can be found without sorting the entire data set. In theory, row_number could work this way also but in practice does not. The difference can be seen by looking at query plans—typically a row_number based query will form the entire result set while a top based approach will seek to the first index entry and then return the next page of rows in the index.<o:p></o:p></FONT></FONT></P>
<P style="MARGIN: 0in 0in 10pt" class=MsoNormal><FONT face=Calibri><FONT size=3>If there is no fixed row order or the result set can change then data can be read into a temporary table and processed by either of the two previous approaches.<o:p></o:p></FONT></FONT></P>
<P style="MARGIN: 0in 0in 10pt" class=MsoNormal><FONT size=3 face=Calibri>ADO.Net has good support for paging data </FONT><A href="https://msdn.microsoft.com/en-us/library/tx1c9c2f.aspx" mce_href="https://msdn.microsoft.com/en-us/library/tx1c9c2f.aspx"><FONT size=3 face=Calibri>https://msdn.microsoft.com/en-us/library/tx1c9c2f.aspx</FONT></A><FONT face=Calibri><FONT size=3>. The Fill method has a specific overload to support paging in of data.<o:p></o:p></FONT></FONT></P>
<P style="MARGIN: 0in 0in 10pt" class=MsoNormal><FONT face=Calibri><FONT size=3>Below I compare the approaches for two interesting performance questions for a table of .Net Framework with 207&nbsp;966 rows:<o:p></o:p></FONT></FONT></P>
<P style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo1" class=MsoListParagraphCxSpFirst><SPAN style="FONT-FAMILY: Symbol; mso-bidi-font-family: Symbol; mso-fareast-font-family: Symbol"><SPAN style="mso-list: Ignore"><FONT size=3>·</FONT><SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN></SPAN><FONT face=Calibri><FONT size=3>What is the cost of retrieving the first page?<o:p></o:p></FONT></FONT></P>
<P style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 10pt 0.5in; mso-list: l0 level1 lfo1" class=MsoListParagraphCxSpLast><SPAN style="FONT-FAMILY: Symbol; mso-bidi-font-family: Symbol; mso-fareast-font-family: Symbol"><SPAN style="mso-list: Ignore"><FONT size=3>·</FONT><SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN></SPAN><FONT size=3><FONT face=Calibri>What is the cost of retrieving all the pages?<o:p></o:p></FONT></FONT></P>
<P style="MARGIN: 0in 0in 10pt" class=MsoNormal><FONT size=3><FONT face=Calibri>Below are the results in seconds to perform the tests 100 times. As always it is wise to not make assumptions in performance or concurrency critical code and to test various approaches yourself.<o:p></o:p></FONT></FONT></P>
<DIV align=center>
<TABLE style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; BORDER-COLLAPSE: collapse; BORDER-TOP: medium none; BORDER-RIGHT: medium none; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt" class=MsoTableGrid border=0 cellSpacing=0 cellPadding=0 class="MsoTableGrid">
<TBODY>
<TR style="mso-yfti-irow: 0; mso-yfti-firstrow: yes">
<TD style="BORDER-BOTTOM: windowtext 1pt solid; BORDER-LEFT: #f0f0f0; PADDING-BOTTOM: 0in; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal align=right><B style="mso-bidi-font-weight: normal"><FONT size=3><FONT face=Calibri>Approach<o:p></o:p></FONT></FONT></B></P></TD>
<TD style="BORDER-BOTTOM: windowtext 1pt solid; BORDER-LEFT: #f0f0f0; PADDING-BOTTOM: 0in; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal><B style="mso-bidi-font-weight: normal"><FONT size=3><FONT face=Calibri>First page (sec)<o:p></o:p></FONT></FONT></B></P></TD>
<TD style="BORDER-BOTTOM: windowtext 1pt solid; BORDER-LEFT: #f0f0f0; PADDING-BOTTOM: 0in; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0; PADDING-TOP: 0in; mso-border-bottom-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal><B style="mso-bidi-font-weight: normal"><FONT size=3><FONT face=Calibri>All pages (sec)<o:p></o:p></FONT></FONT></B></P></TD></TR>
<TR style="mso-yfti-irow: 1">
<TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; PADDING-BOTTOM: 0in; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal align=right><FONT size=3><FONT face=Calibri>Row number<o:p></o:p></FONT></FONT></P></TD>
<TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; PADDING-BOTTOM: 0in; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal align=right><FONT size=3><FONT face=Calibri>2.78<o:p></o:p></FONT></FONT></P></TD>
<TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; PADDING-BOTTOM: 0in; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0; PADDING-TOP: 0in; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal align=right><FONT size=3><FONT face=Calibri>7&nbsp;310.47<o:p></o:p></FONT></FONT></P></TD></TR>
<TR style="mso-yfti-irow: 2">
<TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; PADDING-BOTTOM: 0in; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal align=right><FONT size=3><FONT face=Calibri>Top<o:p></o:p></FONT></FONT></P></TD>
<TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; PADDING-BOTTOM: 0in; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal align=right><FONT size=3><FONT face=Calibri>0.26<o:p></o:p></FONT></FONT></P></TD>
<TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; PADDING-BOTTOM: 0in; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0; PADDING-TOP: 0in; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal align=right><FONT size=3><FONT face=Calibri>51.17<o:p></o:p></FONT></FONT></P></TD></TR>
<TR style="mso-yfti-irow: 3; mso-yfti-lastrow: yes">
<TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; PADDING-BOTTOM: 0in; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal align=right><FONT size=3><FONT face=Calibri>Temporary table<o:p></o:p></FONT></FONT></P></TD>
<TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; PADDING-BOTTOM: 0in; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0in; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal align=right><FONT size=3><FONT face=Calibri>111.13<o:p></o:p></FONT></FONT></P></TD>
<TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; PADDING-BOTTOM: 0in; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0; PADDING-TOP: 0in; mso-border-left-alt: solid windowtext .5pt" vAlign=top>
<P style="TEXT-ALIGN: right; LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal align=right><FONT size=3><FONT face=Calibri>139.94<o:p></o:p></FONT></FONT></P></TD></TR></TBODY></TABLE></DIV>
<P style="MARGIN: 0in 0in 10pt" class=MsoNormal><o:p><FONT size=3 face=Calibri>&nbsp;</FONT></o:p></P>
<P style="MARGIN: 0in 0in 10pt" class=MsoNormal><FONT size=3><FONT face=Calibri>When applicable, the top approach has clear performance advantages. Also it will typically use less server resources than the other approaches.<o:p></o:p></FONT></FONT></P>
<P style="MARGIN: 0in 0in 10pt" class=MsoNormal><FONT size=3><FONT face=Calibri>Here are the test scripts (run with the query option to discard the result set after execution but to collect client statistics).<o:p></o:p></FONT></FONT></P>
<P style="MARGIN: 0in 0in 10pt" class=MsoNormal><SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: Consolas; COLOR: green; FONT-SIZE: 9pt; mso-no-proof: yes">-- row_number approach: First page<BR></SPAN><SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: Consolas; COLOR: blue; FONT-SIZE: 9pt; mso-no-proof: yes">dbcc</SPAN><SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: Consolas; FONT-SIZE: 9pt; mso-no-proof: yes"> freesystemcache<SPAN style="COLOR: blue"> </SPAN><SPAN style="COLOR: gray">(</SPAN><SPAN style="COLOR: red">'All'</SPAN><SPAN style="COLOR: gray">)<BR><BR></SPAN><SPAN style="COLOR: blue">declare</SPAN> @repetitions <SPAN style="COLOR: blue">int</SPAN> <SPAN style="COLOR: gray">=</SPAN> 100<SPAN style="COLOR: gray">;<BR><BR></SPAN><SPAN style="COLOR: blue">declare</SPAN> @i <SPAN style="COLOR: blue">int</SPAN> <SPAN style="COLOR: gray">=</SPAN> 0<SPAN style="COLOR: gray">;<BR></SPAN><SPAN style="COLOR: blue">while</SPAN> @i <SPAN style="COLOR: gray">&lt;</SPAN> @repetitions<BR><SPAN style="COLOR: blue">begin<BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">declare</SPAN> @pageSize <SPAN style="COLOR: blue">bigint</SPAN> <SPAN style="COLOR: gray">=</SPAN> 100<SPAN style="COLOR: gray">;<BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">declare</SPAN> @lastrow <SPAN style="COLOR: blue">bigint</SPAN> <SPAN style="COLOR: gray">=</SPAN><SPAN style="COLOR: blue"> </SPAN><SPAN style="COLOR: gray">(</SPAN><SPAN style="COLOR: blue">select</SPAN> <SPAN style="COLOR: fuchsia">count</SPAN><SPAN style="COLOR: gray">(*)</SPAN> <SPAN style="COLOR: blue">from</SPAN> [System_Runtime]<SPAN style="COLOR: gray">.</SPAN>[Methods]<SPAN style="COLOR: gray">);<BR><BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">declare</SPAN> @startRow <SPAN style="COLOR: blue">bigint</SPAN> <SPAN style="COLOR: gray">=</SPAN> 1<SPAN style="COLOR: gray">;<BR><BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">declare</SPAN> @stopRow <SPAN style="COLOR: blue">bigint</SPAN> <SPAN style="COLOR: gray">=</SPAN> @startRow <SPAN style="COLOR: gray">+</SPAN> @pageSize <SPAN style="COLOR: gray">-</SPAN> 1<SPAN style="COLOR: gray">;<BR><BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">with</SPAN> NumberedResult <SPAN style="COLOR: blue">as<BR><SPAN style="mso-spacerun: yes">&nbsp; </SPAN></SPAN><SPAN style="COLOR: gray">(<BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">select</SPAN> <SPAN style="COLOR: fuchsia">row_number</SPAN><SPAN style="COLOR: gray">()</SPAN> <SPAN style="COLOR: blue">over </SPAN><SPAN style="COLOR: gray">(</SPAN><SPAN style="COLOR: blue">order</SPAN> <SPAN style="COLOR: blue">by</SPAN> M<SPAN style="COLOR: gray">.</SPAN>[Id]<SPAN style="COLOR: gray">)</SPAN> <SPAN style="COLOR: blue">as</SPAN> [Row]<SPAN style="COLOR: gray">,</SPAN> M<SPAN style="COLOR: gray">.</SPAN>[Id]<SPAN style="COLOR: gray">,</SPAN> M<SPAN style="COLOR: gray">.</SPAN>[Name]<BR><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">from</SPAN> [System_Runtime]<SPAN style="COLOR: gray">.</SPAN>[Methods] <SPAN style="COLOR: blue">as</SPAN> M<BR><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: gray">)<BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">select</SPAN> NR<SPAN style="COLOR: gray">.</SPAN>[Id]<SPAN style="COLOR: gray">,</SPAN> NR<SPAN style="COLOR: gray">.</SPAN>[Name]<BR><SPAN style="mso-spacerun: yes">&nbsp;</SPAN><SPAN style="mso-spacerun: yes">&nbsp;</SPAN><SPAN style="COLOR: blue">from</SPAN> NumberedResult <SPAN style="COLOR: blue">as</SPAN> NR<BR><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">where</SPAN> NR<SPAN style="COLOR: gray">.</SPAN>[Row] <SPAN style="COLOR: gray">between</SPAN> @startRow <SPAN style="COLOR: gray">and</SPAN> @stopRow<SPAN style="COLOR: gray">;<BR><BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">set</SPAN> @i <SPAN style="COLOR: gray">+=</SPAN> 1<SPAN style="COLOR: gray">;<BR></SPAN><SPAN style="COLOR: blue">end</SPAN><SPAN style="COLOR: gray">;<BR><BR></SPAN><SPAN style="COLOR: green">-- row_number approach: All pages<BR></SPAN><SPAN style="COLOR: blue">dbcc</SPAN> freesystemcache<SPAN style="COLOR: blue"> </SPAN><SPAN style="COLOR: gray">(</SPAN><SPAN style="COLOR: red">'All'</SPAN><SPAN style="COLOR: gray">)<BR><BR></SPAN><SPAN style="COLOR: blue">declare</SPAN> @repetitions <SPAN style="COLOR: blue">int</SPAN> <SPAN style="COLOR: gray">=</SPAN> 100<SPAN style="COLOR: gray">;<BR><BR></SPAN><SPAN style="COLOR: blue">declare</SPAN> @i <SPAN style="COLOR: blue">int</SPAN> <SPAN style="COLOR: gray">=</SPAN> 0<SPAN style="COLOR: gray">;<BR></SPAN><SPAN style="COLOR: blue">while</SPAN> @i <SPAN style="COLOR: gray">&lt;</SPAN> @repetitions<BR><SPAN style="COLOR: blue">begin<BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">declare</SPAN> @pageSize <SPAN style="COLOR: blue">bigint</SPAN> <SPAN style="COLOR: gray">=</SPAN> 100<SPAN style="COLOR: gray">;<BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">declare</SPAN> @lastrow <SPAN style="COLOR: blue">bigint</SPAN> <SPAN style="COLOR: gray">=</SPAN><SPAN style="COLOR: blue"> </SPAN><SPAN style="COLOR: gray">(</SPAN><SPAN style="COLOR: blue">select</SPAN> <SPAN style="COLOR: fuchsia">count</SPAN><SPAN style="COLOR: gray">(*)</SPAN> <SPAN style="COLOR: blue">from</SPAN> [System_Runtime]<SPAN style="COLOR: gray">.</SPAN>[Methods]<SPAN style="COLOR: gray">);<BR><BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">declare</SPAN> @startRow <SPAN style="COLOR: blue">bigint</SPAN> <SPAN style="COLOR: gray">=</SPAN> 1<SPAN style="COLOR: gray">;<BR><BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">while</SPAN> @startRow <SPAN style="COLOR: gray">&lt;</SPAN> @lastRow<BR><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">begin<BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">declare</SPAN> @stopRow <SPAN style="COLOR: blue">bigint</SPAN> <SPAN style="COLOR: gray">=</SPAN> @startRow <SPAN style="COLOR: gray">+</SPAN> @pageSize <SPAN style="COLOR: gray">-</SPAN> 1<SPAN style="COLOR: gray">;<BR><BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">with</SPAN> NumberedResult <SPAN style="COLOR: blue">as<BR><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN></SPAN><SPAN style="COLOR: gray">(<BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">select</SPAN> <SPAN style="COLOR: fuchsia">row_number</SPAN><SPAN style="COLOR: gray">()</SPAN> <SPAN style="COLOR: blue">over </SPAN><SPAN style="COLOR: gray">(</SPAN><SPAN style="COLOR: blue">order</SPAN> <SPAN style="COLOR: blue">by</SPAN> M<SPAN style="COLOR: gray">.</SPAN>[Id]<SPAN style="COLOR: gray">)</SPAN> <SPAN style="COLOR: blue">as</SPAN> [Row]<SPAN style="COLOR: gray">,</SPAN> M<SPAN style="COLOR: gray">.</SPAN>[Id]<SPAN style="COLOR: gray">,</SPAN> M<SPAN style="COLOR: gray">.</SPAN>[Name]<BR><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">from</SPAN> [System_Runtime]<SPAN style="COLOR: gray">.</SPAN>[Methods] <SPAN style="COLOR: blue">as</SPAN> M<BR><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: gray">)<BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">select</SPAN> NR<SPAN style="COLOR: gray">.</SPAN>[Id]<SPAN style="COLOR: gray">,</SPAN> NR<SPAN style="COLOR: gray">.</SPAN>[Name]<BR><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">from</SPAN> NumberedResult <SPAN style="COLOR: blue">as</SPAN> NR<BR><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">where</SPAN> NR<SPAN style="COLOR: gray">.</SPAN>[Row] <SPAN style="COLOR: gray">between</SPAN> @startRow <SPAN style="COLOR: gray">and</SPAN> @stopRow<SPAN style="COLOR: gray">;<BR><BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">set</SPAN> @startRow <SPAN style="COLOR: gray">+=</SPAN> @pageSize<SPAN style="COLOR: gray">;<BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">end</SPAN><SPAN style="COLOR: gray">;<BR><BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">set</SPAN> @i <SPAN style="COLOR: gray">+=</SPAN> 1<SPAN style="COLOR: gray">;<BR></SPAN><SPAN style="COLOR: blue">end</SPAN><SPAN style="COLOR: gray">;<BR><BR></SPAN><SPAN style="COLOR: green">-- top approach: First page<BR></SPAN><SPAN style="COLOR: blue">dbcc</SPAN> freesystemcache<SPAN style="COLOR: blue"> </SPAN><SPAN style="COLOR: gray">(</SPAN><SPAN style="COLOR: red">'All'</SPAN><SPAN style="COLOR: gray">)<BR><BR></SPAN><SPAN style="COLOR: blue">declare</SPAN> @repetitions <SPAN style="COLOR: blue">int</SPAN> <SPAN style="COLOR: gray">=</SPAN> 100<SPAN style="COLOR: gray">;<BR><BR></SPAN><SPAN style="COLOR: blue">declare</SPAN> @i <SPAN style="COLOR: blue">int</SPAN> <SPAN style="COLOR: gray">=</SPAN> 0<SPAN style="COLOR: gray">;<BR></SPAN><SPAN style="COLOR: blue">while</SPAN> @i <SPAN style="COLOR: gray">&lt;</SPAN> @repetitions<BR><SPAN style="COLOR: blue">begin<BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">declare</SPAN> @pageSize <SPAN style="COLOR: blue">bigint</SPAN> <SPAN style="COLOR: gray">=</SPAN> 100<SPAN style="COLOR: gray">;<BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">declare</SPAN> @maxId <SPAN style="COLOR: blue">bigint</SPAN> <SPAN style="COLOR: gray">=</SPAN><SPAN style="COLOR: blue"> </SPAN><SPAN style="COLOR: gray">(</SPAN><SPAN style="COLOR: blue">select</SPAN> <SPAN style="COLOR: fuchsia">max</SPAN><SPAN style="COLOR: gray">(</SPAN>M<SPAN style="COLOR: gray">.</SPAN>Id<SPAN style="COLOR: gray">)</SPAN> <SPAN style="COLOR: blue">from</SPAN> [System_Runtime]<SPAN style="COLOR: gray">.</SPAN>[Methods] <SPAN style="COLOR: blue">as</SPAN> M<SPAN style="COLOR: gray">);<BR><BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">declare</SPAN> @lastId <SPAN style="COLOR: blue">bigint</SPAN> <SPAN style="COLOR: gray">=</SPAN> 0<SPAN style="COLOR: gray">;<BR><BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">select</SPAN> <SPAN style="COLOR: blue">top</SPAN><SPAN style="COLOR: gray">(</SPAN>@pageSize<SPAN style="COLOR: gray">)</SPAN> M<SPAN style="COLOR: gray">.</SPAN>[Id]<SPAN style="COLOR: gray">,</SPAN> M<SPAN style="COLOR: gray">.</SPAN>[Name]<BR><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">from</SPAN> [System_Runtime]<SPAN style="COLOR: gray">.</SPAN>[Methods] <SPAN style="COLOR: blue">as</SPAN> M<BR><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">where</SPAN> M<SPAN style="COLOR: gray">.</SPAN>[Id] <SPAN style="COLOR: gray">&gt;</SPAN> @lastId<BR><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">order</SPAN> <SPAN style="COLOR: blue">by</SPAN> M<SPAN style="COLOR: gray">.</SPAN>[Id]<BR><BR><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">set</SPAN> @i <SPAN style="COLOR: gray">+=</SPAN> 1<SPAN style="COLOR: gray">;<BR></SPAN><SPAN style="COLOR: blue">end</SPAN><SPAN style="COLOR: gray">;<BR><BR></SPAN><SPAN style="COLOR: green">-- top approach: All pages<BR></SPAN><SPAN style="COLOR: blue">dbcc</SPAN> freesystemcache<SPAN style="COLOR: blue"> </SPAN><SPAN style="COLOR: gray">(</SPAN><SPAN style="COLOR: red">'All'</SPAN><SPAN style="COLOR: gray">)<BR><BR></SPAN><SPAN style="COLOR: blue">declare</SPAN> @repetitions <SPAN style="COLOR: blue">int</SPAN> <SPAN style="COLOR: gray">=</SPAN> 100<SPAN style="COLOR: gray">;<BR><BR></SPAN><SPAN style="COLOR: blue">declare</SPAN> @i <SPAN style="COLOR: blue">int</SPAN> <SPAN style="COLOR: gray">=</SPAN> 0<SPAN style="COLOR: gray">;<BR></SPAN><SPAN style="COLOR: blue">while</SPAN> @i <SPAN style="COLOR: gray">&lt;</SPAN> @repetitions<BR><SPAN style="COLOR: blue">begin<BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">declare</SPAN> @pageSize <SPAN style="COLOR: blue">bigint</SPAN> <SPAN style="COLOR: gray">=</SPAN> 100<SPAN style="COLOR: gray">;<BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">declare</SPAN> @maxId <SPAN style="COLOR: blue">bigint</SPAN> <SPAN style="COLOR: gray">=</SPAN><SPAN style="COLOR: blue"> </SPAN><SPAN style="COLOR: gray">(</SPAN><SPAN style="COLOR: blue">select</SPAN> <SPAN style="COLOR: fuchsia">max</SPAN><SPAN style="COLOR: gray">(</SPAN>M<SPAN style="COLOR: gray">.</SPAN>Id<SPAN style="COLOR: gray">)</SPAN> <SPAN style="COLOR: blue">from</SPAN> [System_Runtime]<SPAN style="COLOR: gray">.</SPAN>[Methods] <SPAN style="COLOR: blue">as</SPAN> M<SPAN style="COLOR: gray">);<BR><BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">declare</SPAN> @lastId <SPAN style="COLOR: blue">bigint</SPAN> <SPAN style="COLOR: gray">=</SPAN> 0<SPAN style="COLOR: gray">;<BR><BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">while</SPAN> @lastId <SPAN style="COLOR: gray">&lt;</SPAN> @maxId<BR><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">begin<BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">select</SPAN> <SPAN style="COLOR: blue">top</SPAN><SPAN style="COLOR: gray">(</SPAN>@pageSize<SPAN style="COLOR: gray">)</SPAN> M<SPAN style="COLOR: gray">.</SPAN>[Id]<SPAN style="COLOR: gray">,</SPAN> M<SPAN style="COLOR: gray">.</SPAN>[Name]<BR><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">from</SPAN> [System_Runtime]<SPAN style="COLOR: gray">.</SPAN>[Methods] <SPAN style="COLOR: blue">as</SPAN> M<BR><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">where</SPAN> M<SPAN style="COLOR: gray">.</SPAN>[Id] <SPAN style="COLOR: gray">&gt;</SPAN> @lastId<BR><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">order</SPAN> <SPAN style="COLOR: blue">by</SPAN> M<SPAN style="COLOR: gray">.</SPAN>[Id]<BR><BR><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">set</SPAN> @lastId <SPAN style="COLOR: gray">+=</SPAN> @pageSize<SPAN style="COLOR: gray">;<BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">end</SPAN><SPAN style="COLOR: gray">;<BR><BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">set</SPAN> @i <SPAN style="COLOR: gray">+=</SPAN> 1<SPAN style="COLOR: gray">;<BR></SPAN><SPAN style="COLOR: blue">end</SPAN><SPAN style="COLOR: gray">;<BR><BR></SPAN><SPAN style="COLOR: green">-- temporary table approach: First page<BR></SPAN><SPAN style="COLOR: blue">dbcc</SPAN> freesystemcache<SPAN style="COLOR: blue"> </SPAN><SPAN style="COLOR: gray">(</SPAN><SPAN style="COLOR: red">'All'</SPAN><SPAN style="COLOR: gray">)<BR><BR></SPAN><SPAN style="COLOR: blue">declare</SPAN> @repetitions <SPAN style="COLOR: blue">int</SPAN> <SPAN style="COLOR: gray">=</SPAN> 100<SPAN style="COLOR: gray">;<BR><BR></SPAN><SPAN style="COLOR: blue">declare</SPAN> @i <SPAN style="COLOR: blue">int</SPAN> <SPAN style="COLOR: gray">=</SPAN> 0<SPAN style="COLOR: gray">;<BR></SPAN><SPAN style="COLOR: blue">while</SPAN> @i <SPAN style="COLOR: gray">&lt;</SPAN> @repetitions<BR><SPAN style="COLOR: blue">begin<BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">declare</SPAN> @pageSize <SPAN style="COLOR: blue">bigint</SPAN> <SPAN style="COLOR: gray">=</SPAN> 100<SPAN style="COLOR: gray">;<BR><BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">create</SPAN> <SPAN style="COLOR: blue">table</SPAN> #results<BR><SPAN style="COLOR: blue"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN></SPAN><SPAN style="COLOR: gray">(<BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>[Row]<SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">bigint</SPAN> <SPAN style="COLOR: gray">not</SPAN> <SPAN style="COLOR: gray">null</SPAN> <SPAN style="COLOR: blue">primary</SPAN> <SPAN style="COLOR: blue">key</SPAN><SPAN style="COLOR: gray">,<BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>[Id]<SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">bigint</SPAN> <SPAN style="COLOR: gray">not</SPAN> <SPAN style="COLOR: gray">null,<BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>[Name] <SPAN style="COLOR: blue">nvarchar</SPAN><SPAN style="COLOR: gray">(</SPAN><SPAN style="COLOR: fuchsia">max</SPAN><SPAN style="COLOR: gray">)</SPAN> <SPAN style="COLOR: gray">not</SPAN> <SPAN style="COLOR: gray">null<BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: gray">);<BR><BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">insert</SPAN> <SPAN style="COLOR: blue">into</SPAN> #results<SPAN style="COLOR: blue"> </SPAN><SPAN style="COLOR: gray">(</SPAN>[Row]<SPAN style="COLOR: gray">,</SPAN> [Id]<SPAN style="COLOR: gray">,</SPAN> [Name]<SPAN style="COLOR: gray">)<BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">select</SPAN> <SPAN style="COLOR: fuchsia">row_number</SPAN><SPAN style="COLOR: gray">()</SPAN> <SPAN style="COLOR: blue">over </SPAN><SPAN style="COLOR: gray">(</SPAN><SPAN style="COLOR: blue">order</SPAN> <SPAN style="COLOR: blue">by</SPAN> M<SPAN style="COLOR: gray">.</SPAN>[Id]<SPAN style="COLOR: gray">)</SPAN> <SPAN style="COLOR: blue">as</SPAN> [Row]<SPAN style="COLOR: gray">,</SPAN> M<SPAN style="COLOR: gray">.</SPAN>[Id]<SPAN style="COLOR: gray">,</SPAN> M<SPAN style="COLOR: gray">.</SPAN>[Name]<BR><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">from</SPAN> [System_Runtime]<SPAN style="COLOR: gray">.</SPAN>[Methods] <SPAN style="COLOR: blue">as</SPAN> M<BR><BR><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">declare</SPAN> @startRow <SPAN style="COLOR: blue">bigint</SPAN> <SPAN style="COLOR: gray">=</SPAN> 1<SPAN style="COLOR: gray">;<BR><BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">declare</SPAN> @stopRow <SPAN style="COLOR: blue">bigint</SPAN> <SPAN style="COLOR: gray">=</SPAN> @startRow <SPAN style="COLOR: gray">+</SPAN> @pageSize <SPAN style="COLOR: gray">-</SPAN> 1<SPAN style="COLOR: gray">;<BR><BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">select</SPAN> R<SPAN style="COLOR: gray">.</SPAN>[Id]<SPAN style="COLOR: gray">,</SPAN> R<SPAN style="COLOR: gray">.</SPAN>[Name]<BR><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">from</SPAN> #results <SPAN style="COLOR: blue">as</SPAN> R<BR><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">where</SPAN> R<SPAN style="COLOR: gray">.</SPAN>[Row] <SPAN style="COLOR: gray">between</SPAN> @startRow <SPAN style="COLOR: gray">and</SPAN> @stopRow<SPAN style="COLOR: gray">;<BR><BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">drop</SPAN> <SPAN style="COLOR: blue">table</SPAN> #results<SPAN style="COLOR: gray">;<BR><BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">set</SPAN> @i <SPAN style="COLOR: gray">+=</SPAN> 1<SPAN style="COLOR: gray">;<BR></SPAN><SPAN style="COLOR: blue">end</SPAN><SPAN style="COLOR: gray">;<BR><BR></SPAN><SPAN style="COLOR: green">-- temporary table approach: All pages<BR></SPAN><SPAN style="COLOR: blue">dbcc</SPAN> freesystemcache<SPAN style="COLOR: blue"> </SPAN><SPAN style="COLOR: gray">(</SPAN><SPAN style="COLOR: red">'All'</SPAN><SPAN style="COLOR: gray">)<BR><BR></SPAN><SPAN style="COLOR: blue">declare</SPAN> @repetitions <SPAN style="COLOR: blue">int</SPAN> <SPAN style="COLOR: gray">=</SPAN> 100<SPAN style="COLOR: gray">;<BR><BR></SPAN><SPAN style="COLOR: blue">declare</SPAN> @i <SPAN style="COLOR: blue">int</SPAN> <SPAN style="COLOR: gray">=</SPAN> 0<SPAN style="COLOR: gray">;<BR></SPAN><SPAN style="COLOR: blue">while</SPAN> @i <SPAN style="COLOR: gray">&lt;</SPAN> @repetitions<BR><SPAN style="COLOR: blue">begin<BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">declare</SPAN> @pageSize <SPAN style="COLOR: blue">bigint</SPAN> <SPAN style="COLOR: gray">=</SPAN> 100<SPAN style="COLOR: gray">;<BR><BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">create</SPAN> <SPAN style="COLOR: blue">table</SPAN> #results<BR><SPAN style="COLOR: blue"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN></SPAN><SPAN style="COLOR: gray">(<BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>[Row]<SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">bigint</SPAN> <SPAN style="COLOR: gray">not</SPAN> <SPAN style="COLOR: gray">null</SPAN> <SPAN style="COLOR: blue">primary</SPAN> <SPAN style="COLOR: blue">key</SPAN><SPAN style="COLOR: gray">,<BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>[Id]<SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">bigint</SPAN> <SPAN style="COLOR: gray">not</SPAN> <SPAN style="COLOR: gray">null,<BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>[Name] <SPAN style="COLOR: blue">nvarchar</SPAN><SPAN style="COLOR: gray">(</SPAN><SPAN style="COLOR: fuchsia">max</SPAN><SPAN style="COLOR: gray">)</SPAN> <SPAN style="COLOR: gray">not</SPAN> <SPAN style="COLOR: gray">null<BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: gray">);<BR><BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">insert</SPAN> <SPAN style="COLOR: blue">into</SPAN> #results<SPAN style="COLOR: blue"> </SPAN><SPAN style="COLOR: gray">(</SPAN>[Row]<SPAN style="COLOR: gray">,</SPAN> [Id]<SPAN style="COLOR: gray">,</SPAN> [Name]<SPAN style="COLOR: gray">)<BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">select</SPAN> <SPAN style="COLOR: fuchsia">row_number</SPAN><SPAN style="COLOR: gray">()</SPAN> <SPAN style="COLOR: blue">over </SPAN><SPAN style="COLOR: gray">(</SPAN><SPAN style="COLOR: blue">order</SPAN> <SPAN style="COLOR: blue">by</SPAN> M<SPAN style="COLOR: gray">.</SPAN>[Id]<SPAN style="COLOR: gray">)</SPAN> <SPAN style="COLOR: blue">as</SPAN> [Row]<SPAN style="COLOR: gray">,</SPAN> M<SPAN style="COLOR: gray">.</SPAN>[Id]<SPAN style="COLOR: gray">,</SPAN> M<SPAN style="COLOR: gray">.</SPAN>[Name]<BR><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">from</SPAN> [System_Runtime]<SPAN style="COLOR: gray">.</SPAN>[Methods] <SPAN style="COLOR: blue">as</SPAN> M<BR><BR><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">declare</SPAN> @lastrow <SPAN style="COLOR: blue">bigint</SPAN> <SPAN style="COLOR: gray">=</SPAN><SPAN style="COLOR: blue"> </SPAN><SPAN style="COLOR: gray">(</SPAN><SPAN style="COLOR: blue">select</SPAN> <SPAN style="COLOR: fuchsia">count</SPAN><SPAN style="COLOR: gray">(*)</SPAN> <SPAN style="COLOR: blue">from</SPAN> #results<SPAN style="COLOR: gray">);<BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">declare</SPAN> @startRow <SPAN style="COLOR: blue">bigint</SPAN> <SPAN style="COLOR: gray">=</SPAN> 1<SPAN style="COLOR: gray">;<BR><BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">while</SPAN> @startRow <SPAN style="COLOR: gray">&lt;</SPAN> @lastRow<BR><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">begin<BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">declare</SPAN> @stopRow <SPAN style="COLOR: blue">bigint</SPAN> <SPAN style="COLOR: gray">=</SPAN> @startRow <SPAN style="COLOR: gray">+</SPAN> @pageSize <SPAN style="COLOR: gray">-</SPAN> 1<SPAN style="COLOR: gray">;<BR><BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">select</SPAN> R<SPAN style="COLOR: gray">.</SPAN>[Id]<SPAN style="COLOR: gray">,</SPAN> R<SPAN style="COLOR: gray">.</SPAN>[Name]<BR><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">from</SPAN> #results <SPAN style="COLOR: blue">as</SPAN> R<BR><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">where</SPAN> R<SPAN style="COLOR: gray">.</SPAN>[Row] <SPAN style="COLOR: gray">between</SPAN> @startRow <SPAN style="COLOR: gray">and</SPAN> @stopRow<SPAN style="COLOR: gray">;<BR><BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">set</SPAN> @startRow <SPAN style="COLOR: gray">+=</SPAN> @pageSize<SPAN style="COLOR: gray">;<BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">end</SPAN><SPAN style="COLOR: gray">;<BR><BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">drop</SPAN> <SPAN style="COLOR: blue">table</SPAN> #results<SPAN style="COLOR: gray">;<BR><BR></SPAN><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">set</SPAN> @i <SPAN style="COLOR: gray">+=</SPAN> 1<SPAN style="COLOR: gray">;<BR></SPAN><SPAN style="COLOR: blue">end</SPAN><SPAN style="COLOR: gray">;<BR style="mso-special-character: line-break"><BR style="mso-special-character: line-break"></SPAN></SPAN><SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: Consolas; FONT-SIZE: 9pt"><o:p></o:p></SPAN></P>]]></content:encoded>
    </item>
    <item>
      <title>"Oslo" repository lifecycle/versioning whitepaper</title>
      <link>https://docs.microsoft.com/archive/blogs/anthonybloesch/oslo-repository-lifecycleversioning-whitepaper</link>
      <pubDate>Tue, 07 Apr 2009 12:44:00 GMT</pubDate>
      <dc:creator><![CDATA[Anthony Bloesch]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/anthonybloesch/2009/04/07/oslo-repository-lifecycleversioning-whitepaper/</guid>
      <description><![CDATA[Repositories face issues to do with versioning schema and data as well as integrating with an...]]></description>
      <content:encoded><![CDATA[<P style="MARGIN: 0in 0in 6pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Candara','sans-serif'"><FONT size=3>Repositories face issues to do with versioning schema and data as well as integrating with an organization's lifecycle processes. Here is a whitepaper I wrote on how&nbsp;the "Oslo" team&nbsp;thinks about handling various lifecycle/versioning issues </FONT><A href="https://msdn.microsoft.com/en-us/library/dd638048.aspx"><FONT size=3>https://msdn.microsoft.com/en-us/library/dd638048.aspx</FONT></A><FONT size=3>. The whitepaper deals with the following issues:<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></FONT></SPAN></P>
<P style="MARGIN: 0in 0in 6pt 0.5in" class=MsoListParagraph><FONT size=3><FONT face=Calibri><B style="mso-bidi-font-weight: normal">Application lifecycle management (ALM)</B>: Facilitating team development of software in a continuous cycle of steps (that is, definition, design, development, testing, deployment, and management). Traditionally, Source Code Control Systems (SCCS) and build systems, like Visual Studio Team Foundation Server, automate ALM. </FONT></FONT></P>
<P style="MARGIN: 0in 0in 6pt 0.5in" class=MsoListParagraph><FONT size=3><FONT face=Calibri><B style="mso-bidi-font-weight: normal">Schema evolution</B>: Changing schemas over time in such a way that applications continue to run unchanged or with minimal changes. </FONT></FONT></P>
<P style="MARGIN: 0in 0in 6pt 0.5in" class=MsoListParagraph><FONT size=3><FONT face=Calibri><B style="mso-bidi-font-weight: normal">"Oslo" product versioning</B>: Upgrading a customer's "Oslo" repository, from version n to version n+1, in such a way that the data is preserved. </FONT></FONT></P>
<P style="MARGIN: 0in 0in 6pt 0.5in" class=MsoListParagraph><FONT size=3><FONT face=Calibri><B style="mso-bidi-font-weight: normal">Application versioning</B>: The ability to upgrade applications, stored in the "Oslo" repository, to new versions. The upgrade process has the option to retain the data from older versions of the application. </FONT></FONT></P>
<P style="MARGIN: 0in 0in 6pt 0.5in" class=MsoListParagraph><FONT size=3><FONT face=Calibri><B style="mso-bidi-font-weight: normal">Operational versioning</B>: The ability to understand operational/management changes to a deployed application.</FONT></FONT></P>]]></content:encoded>
    </item>
    <item>
      <title>How to make a copy of the repository</title>
      <link>https://docs.microsoft.com/archive/blogs/anthonybloesch/how-to-make-a-copy-of-the-repository</link>
      <pubDate>Mon, 06 Apr 2009 19:22:00 GMT</pubDate>
      <dc:creator><![CDATA[Anthony Bloesch]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/anthonybloesch/2009/04/06/how-to-make-a-copy-of-the-repository/</guid>
      <description><![CDATA[Here is a nice article on how to make a copy of the “Oslo” repository so you can later restore it to...]]></description>
      <content:encoded><![CDATA[<P style="MARGIN: 0in 0in 10pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Candara','sans-serif'"><FONT size=3>Here is a nice article on how to make a copy of the “Oslo” repository so you can later restore it to its previous state </FONT><A href="https://blogs.msdn.com/modelcitizen/archive/2009/04/06/how-to-clean-up-the-repository.aspx"><FONT size=3>https://blogs.msdn.com/modelcitizen/archive/2009/04/06/how-to-clean-up-the-repository.aspx</FONT></A><FONT size=3>. This is great for experimenting with the repository and for edit debug cycles with domains. The steps are essentially what we do internally at Microsoft.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></FONT></SPAN></P>]]></content:encoded>
    </item>
  </channel>
</rss>