<?xml version="1.0" encoding="utf-8"?><!-- generator="b2evolution/6.11.7-stable" -->
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:admin="http://webns.net/mvcb/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>Holger Schmeling</title>
		<link>https://www.insidesql.org/blogs/holgerschmeling/</link>
		<atom:link rel="self" type="application/rss+xml" href="https://www.insidesql.org/blogs/holgerschmeling/?tempskin=_rss2" />
		<description>InsideSQL.org Blogs - Blogs über SQL Server</description>
		<language>en-EU</language>
		<docs>http://blogs.law.harvard.edu/tech/rss</docs>
		<admin:generatorAgent rdf:resource="http://b2evolution.net/?v=6.11.7-stable"/>
		<ttl>60</ttl>
				<item>
			<title>Configuring a server side trace</title>
			<link>https://www.insidesql.org/blogs/holgerschmeling/2011/11/01/configuring-a-server-side-trace</link>
			<pubDate>Tue, 01 Nov 2011 11:43:00 +0000</pubDate>			<dc:creator>Holger Schmeling</dc:creator>
			<category domain="main">SQL Server Performance</category>			<guid isPermaLink="false">3044@https://www.insidesql.org/blogs/</guid>
						<description>&lt;p&gt;When I&#039;m after SQL Server performance&amp;#160; problems, SQL Server Profiler is still my number one tool. Allthough I know that extended events provide a mor lightweight solution, those are still a bit cumbersome to use (but I&#039;ve seen that we can expect some improvements with SQL Server 2012).&lt;/p&gt;  &lt;p&gt;When I&#039;m using profiler to isolate performance issues, I try to configure server side traces, whenever possible. Fortunately, SQL Server Profiler will help you creating a script for a server side trace (File/Export/Script Trace Definition), so you don&#039;t have to figure out all the event- and column-codes. Very good!&lt;/p&gt;  &lt;p&gt;As I was doing the same configuration again and again, I decided to separate the TSQL code for the configuration inside a stored procedure.&lt;/p&gt;  &lt;p&gt;And here comes dbo.configureServerSideTrace:&lt;/p&gt;  &lt;table style=&quot;border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8db3e2; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8db3e2; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102&quot; class=&quot;MsoTableGrid&quot; border=&quot;1&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; width=&quot;1315&quot;&gt;&lt;tbody&gt;     &lt;tr style=&quot;mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes&quot;&gt;       &lt;td style=&quot;border-bottom: #8db3e2 1pt dashed; border-left: #8db3e2 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; border-top: #8db3e2 1pt dashed; border-right: #8db3e2 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102&quot; valign=&quot;top&quot; width=&quot;1313&quot;&gt;         &lt;p style=&quot;line-height: normal; margin: 6pt 0in&quot; class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: ; color: ; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-ansi-language: en-us; mso-no-proof: yes&quot; lang=&quot;EN-US&quot;&gt;&lt;font color=&quot;#0000ff&quot; face=&quot;Lucida Console&quot;&gt;&lt;font style=&quot;font-size: 10pt&quot;&gt;if&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;font style=&quot;font-size: 10pt&quot;&gt;&lt;span style=&quot;font-family: ; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-ansi-language: en-us; mso-no-proof: yes&quot; lang=&quot;EN-US&quot;&gt;&lt;font face=&quot;Lucida Console&quot;&gt;&lt;font color=&quot;#000000&quot;&gt; &lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#ff00ff&quot;&gt;object_id&lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;(&lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#ff0000&quot;&gt;&#039;dbo.configureServerSideTrace&#039;&lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; &lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#ff0000&quot;&gt;&#039;P&#039;&lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;)&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; &lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;is&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; &lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;not&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; &lt;/font&gt;&lt;/font&gt;&lt;font face=&quot;Lucida Console&quot;&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;null&lt;/font&gt;                     &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;font color=&quot;#000000&quot;&gt;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt;drop&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; &lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt;procedure&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; dbo&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;.&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt;configureServerSideTrace&lt;/font&gt;                   &lt;br /&gt;&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font face=&quot;Lucida Console&quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt;go&lt;/font&gt;                     &lt;br /&gt;                    &lt;br /&gt;&lt;/font&gt;&lt;/span&gt;&lt;font face=&quot;Lucida Console&quot;&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#008000&quot;&gt;-- Example for:                      &lt;br /&gt;-- Start Trace                       &lt;br /&gt;--&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&amp;#160;&amp;#160; &lt;/span&gt;declare @traceID int                       &lt;br /&gt;--&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&amp;#160;&amp;#160; &lt;/span&gt;exec dbo.configureServerSideTrace @traceStatus = 1                       &lt;br /&gt;--&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;,@traceID = @traceID output                       &lt;br /&gt;--&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;,@maxFileSize = 10000                       &lt;br /&gt;--&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;,@traceFileName = N&#039;e:\VMITrace\Undo&#039;                       &lt;br /&gt;--&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;,@spId = @@spid                       &lt;br /&gt;--                       &lt;br /&gt;-- End Trace                       &lt;br /&gt;--&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&amp;#160;&amp;#160; &lt;/span&gt;exec dbo.configureServerSideTrace @traceStatus = 0, @traceID = @traceID&lt;/font&gt;                     &lt;br /&gt;                    &lt;br /&gt;                    &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt;create&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; &lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt;procedure&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; dbo&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;.&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt;configureServerSideTrace&lt;/font&gt;                   &lt;br /&gt;&lt;span style=&quot;color: &quot;&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;(&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt;@traceStatus&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&amp;#160;&amp;#160; &lt;/span&gt;&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt;bit&lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;font color=&quot;#000000&quot;&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;font face=&quot;Lucida Console&quot;&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#008000&quot;&gt;-- 1 =&amp;gt; Start Trace&lt;/font&gt;                     &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;font color=&quot;#000000&quot;&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;font face=&quot;Lucida Console&quot;&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#008000&quot;&gt;-- 0 =&amp;gt; Stop Trace&lt;/font&gt;                     &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;font color=&quot;#000000&quot;&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt;@traceID&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt;int&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; &lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt;output&lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;font color=&quot;#000000&quot;&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;font face=&quot;Lucida Console&quot;&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#008000&quot;&gt;-- If the Trace is started, this param will return the TraceID&lt;/font&gt;                     &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;font color=&quot;#000000&quot;&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;font face=&quot;Lucida Console&quot;&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#008000&quot;&gt;-- For stopping the trace, the param has to be provided&lt;/font&gt;                     &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;font color=&quot;#000000&quot;&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt;@spId&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt;int&lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;font color=&quot;#000000&quot;&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;=&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; &lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;null&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; &lt;/font&gt;&lt;/font&gt;&lt;font face=&quot;Lucida Console&quot;&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#008000&quot;&gt;-- provide the @@spid, if you want to filter only events for this conection&lt;/font&gt;                     &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;font color=&quot;#000000&quot;&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;font face=&quot;Lucida Console&quot;&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#008000&quot;&gt;-- Optional. If not provided =&amp;gt; no filter. Not needed for stopping the trace&lt;/font&gt;                     &lt;br /&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&amp;#160;&amp;#160; &lt;/span&gt;&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt;@maxFileSize&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&amp;#160;&amp;#160; &lt;/span&gt;&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt;bigint&lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;font color=&quot;#000000&quot;&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;=&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 5000 &lt;/font&gt;&lt;/font&gt;&lt;font face=&quot;Lucida Console&quot;&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#008000&quot;&gt;-- Maximum Trace File Size in Megabyte. Trace will be stopped, if the filesize is reached.&lt;/font&gt;                     &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;font color=&quot;#000000&quot;&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt;@traceFileName &lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt;nvarchar&lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;(&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt;200&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;)&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; &lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;=&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; &lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;null&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; &lt;/font&gt;&lt;/font&gt;&lt;font face=&quot;Lucida Console&quot;&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#008000&quot;&gt;-- Name of the trace file (server side!)&lt;/font&gt;                     &lt;br /&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face=&quot;Lucida Console&quot;&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#008000&quot;&gt;-- Optional. Not neded for stoping the trace&lt;/font&gt;                     &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;font color=&quot;#000000&quot;&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;font face=&quot;Lucida Console&quot;&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#008000&quot;&gt;-- Attention! If the file already exists, the SP will yield an error&lt;/font&gt;                     &lt;br /&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face=&quot;Lucida Console&quot;&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#008000&quot;&gt;-- and no trace is started.&lt;/font&gt;                     &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;font color=&quot;#000000&quot;&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;)&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; &lt;/font&gt;&lt;/font&gt;&lt;font face=&quot;Lucida Console&quot;&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt;as                      &lt;br /&gt;begin                       &lt;br /&gt;                      &lt;br /&gt;if &lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;(&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt;@traceStatus &lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;=&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 0&lt;/font&gt;&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font face=&quot;Lucida Console&quot;&gt;&lt;font color=&quot;#808080&quot;&gt;)&lt;/font&gt;                     &lt;br /&gt;&lt;/font&gt;&lt;/span&gt;&lt;font face=&quot;Lucida Console&quot;&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt;begin&lt;/font&gt;                     &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;font color=&quot;#000000&quot;&gt;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt;exec&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; &lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#800000&quot;&gt;sp_trace_setstatus&lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt; &lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt;@TraceID&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;font face=&quot;Lucida Console&quot;&gt;&lt;font color=&quot;#000000&quot;&gt; 0                    &lt;br /&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&amp;#160;&amp;#160; &lt;/span&gt;&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt;exec&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; &lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#800000&quot;&gt;sp_trace_setstatus&lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt; &lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt;@TraceID&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;font face=&quot;Lucida Console&quot;&gt;&lt;font color=&quot;#000000&quot;&gt; 2                    &lt;br /&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&amp;#160;&amp;#160; &lt;/span&gt;&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt;return&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font face=&quot;Lucida Console&quot;&gt;&lt;font color=&quot;#808080&quot;&gt;;&lt;/font&gt;                     &lt;br /&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font face=&quot;Lucida Console&quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt;end&lt;/font&gt;                     &lt;br /&gt;                    &lt;br /&gt;&lt;/font&gt;&lt;/span&gt;&lt;font face=&quot;Lucida Console&quot;&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#008000&quot;&gt;-- Create a Queue&lt;/font&gt;                     &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt;declare&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; @rc &lt;/font&gt;&lt;/font&gt;&lt;font face=&quot;Lucida Console&quot;&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt;int                      &lt;br /&gt;                      &lt;br /&gt;exec&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; @rc &lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;=&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; &lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#800000&quot;&gt;sp_trace_create&lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt; &lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt;@TraceID &lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt;output&lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 0&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; @traceFileName&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; @maxfilesize&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; &lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;NULL&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; &lt;/font&gt;                  &lt;br /&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt;if &lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;(&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt;@rc &lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;!=&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 0&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;)&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; &lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt;goto&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; error&lt;/font&gt;                   &lt;br /&gt;                  &lt;br /&gt;&lt;/font&gt;&lt;font face=&quot;Lucida Console&quot;&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#008000&quot;&gt;-- Set the events&lt;/font&gt;                     &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt;declare&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; @on &lt;/font&gt;&lt;/font&gt;&lt;font face=&quot;Lucida Console&quot;&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt;bit                      &lt;br /&gt;set&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; @on &lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;=&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 1&lt;/font&gt;                   &lt;br /&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt;exec&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; &lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#800000&quot;&gt;sp_trace_setevent&lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt; &lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt;@TraceID&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 43&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 15&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; @on&lt;/font&gt;                   &lt;br /&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt;exec&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; &lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#800000&quot;&gt;sp_trace_setevent&lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt; &lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt;@TraceID&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 43&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 48&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; @on&lt;/font&gt;                   &lt;br /&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt;exec&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; &lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#800000&quot;&gt;sp_trace_setevent&lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt; &lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt;@TraceID&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 43&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 1&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; @on&lt;/font&gt;                   &lt;br /&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt;exec&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; &lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#800000&quot;&gt;sp_trace_setevent&lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt; &lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt;@TraceID&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 43&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 34&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; @on&lt;/font&gt;                   &lt;br /&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt;exec&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; &lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#800000&quot;&gt;sp_trace_setevent&lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt; &lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt;@TraceID&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 43&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 35&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; @on&lt;/font&gt;                   &lt;br /&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt;exec&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; &lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#800000&quot;&gt;sp_trace_setevent&lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt; &lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt;@TraceID&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 43&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 51&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; @on&lt;/font&gt;                   &lt;br /&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt;exec&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; &lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#800000&quot;&gt;sp_trace_setevent&lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt; &lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt;@TraceID&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 43&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 4&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; @on&lt;/font&gt;                   &lt;br /&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt;exec&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; &lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#800000&quot;&gt;sp_trace_setevent&lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt; &lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt;@TraceID&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 43&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 12&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; @on&lt;/font&gt;                   &lt;br /&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt;exec&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; &lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#800000&quot;&gt;sp_trace_setevent&lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt; &lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt;@TraceID&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 43&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 13&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; @on&lt;/font&gt;                   &lt;br /&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt;exec&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; &lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#800000&quot;&gt;sp_trace_setevent&lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt; &lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt;@TraceID&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 43&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 14&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; @on&lt;/font&gt;                   &lt;br /&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt;exec&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; &lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#800000&quot;&gt;sp_trace_setevent&lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt; &lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt;@TraceID&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 43&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 22&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; @on&lt;/font&gt;                   &lt;br /&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt;exec&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; &lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#800000&quot;&gt;sp_trace_setevent&lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt; &lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt;@TraceID&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 42&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 1&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; @on&lt;/font&gt;                   &lt;br /&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt;exec&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; &lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#800000&quot;&gt;sp_trace_setevent&lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt; &lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt;@TraceID&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 42&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 14&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; @on&lt;/font&gt;                   &lt;br /&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt;exec&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; &lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#800000&quot;&gt;sp_trace_setevent&lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt; &lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt;@TraceID&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 42&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 22&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; @on&lt;/font&gt;                   &lt;br /&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt;exec&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; &lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#800000&quot;&gt;sp_trace_setevent&lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt; &lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt;@TraceID&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 42&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 34&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; @on&lt;/font&gt;                   &lt;br /&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt;exec&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; &lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#800000&quot;&gt;sp_trace_setevent&lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt; &lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt;@TraceID&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 42&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 35&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; @on&lt;/font&gt;                   &lt;br /&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt;exec&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; &lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#800000&quot;&gt;sp_trace_setevent&lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt; &lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt;@TraceID&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 42&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 51&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; @on&lt;/font&gt;                   &lt;br /&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt;exec&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; &lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#800000&quot;&gt;sp_trace_setevent&lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt; &lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt;@TraceID&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 42&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 4&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; @on&lt;/font&gt;                   &lt;br /&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt;exec&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; &lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#800000&quot;&gt;sp_trace_setevent&lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt; &lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt;@TraceID&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 42&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 12&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; @on&lt;/font&gt;                   &lt;br /&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt;exec&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; &lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#800000&quot;&gt;sp_trace_setevent&lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt; &lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt;@TraceID&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 45&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 16&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; @on&lt;/font&gt;                   &lt;br /&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt;exec&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; &lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#800000&quot;&gt;sp_trace_setevent&lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt; &lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt;@TraceID&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 45&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 48&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; @on&lt;/font&gt;                   &lt;br /&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt;exec&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; &lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#800000&quot;&gt;sp_trace_setevent&lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt; &lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt;@TraceID&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 45&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 1&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; @on&lt;/font&gt;                   &lt;br /&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt;exec&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; &lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#800000&quot;&gt;sp_trace_setevent&lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt; &lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt;@TraceID&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 45&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 17&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; @on&lt;/font&gt;                   &lt;br /&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt;exec&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; &lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#800000&quot;&gt;sp_trace_setevent&lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt; &lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt;@TraceID&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 45&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 18&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; @on&lt;/font&gt;                   &lt;br /&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt;exec&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; &lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#800000&quot;&gt;sp_trace_setevent&lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt; &lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt;@TraceID&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 45&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 34&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; @on&lt;/font&gt;                   &lt;br /&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt;exec&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; &lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#800000&quot;&gt;sp_trace_setevent&lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt; &lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt;@TraceID&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 45&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 35&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; @on&lt;/font&gt;                   &lt;br /&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt;exec&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; &lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#800000&quot;&gt;sp_trace_setevent&lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt; &lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt;@TraceID&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 45&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 51&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; @on&lt;/font&gt;                   &lt;br /&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt;exec&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; &lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#800000&quot;&gt;sp_trace_setevent&lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt; &lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt;@TraceID&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 45&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 4&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; @on&lt;/font&gt;                   &lt;br /&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt;exec&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; &lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#800000&quot;&gt;sp_trace_setevent&lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt; &lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt;@TraceID&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 45&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 12&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; @on&lt;/font&gt;                   &lt;br /&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt;exec&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; &lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#800000&quot;&gt;sp_trace_setevent&lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt; &lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt;@TraceID&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 45&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 13&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; @on&lt;/font&gt;                   &lt;br /&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt;exec&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; &lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#800000&quot;&gt;sp_trace_setevent&lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt; &lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt;@TraceID&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 45&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 14&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; @on&lt;/font&gt;                   &lt;br /&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt;exec&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; &lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#800000&quot;&gt;sp_trace_setevent&lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt; &lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt;@TraceID&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 45&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 22&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; @on&lt;/font&gt;                   &lt;br /&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt;exec&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; &lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#800000&quot;&gt;sp_trace_setevent&lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt; &lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt;@TraceID&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 45&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 15&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; @on&lt;/font&gt;                   &lt;br /&gt;&lt;/font&gt;&lt;font face=&quot;Lucida Console&quot;&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#008000&quot;&gt;-- XML Statistics Profile&lt;/font&gt;                     &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt;exec&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; &lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#800000&quot;&gt;sp_trace_setevent&lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt; &lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt;@TraceID&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 146&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 1&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; @on&lt;/font&gt;                   &lt;br /&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt;exec&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; &lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#800000&quot;&gt;sp_trace_setevent&lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt; &lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt;@TraceID&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 146&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 51&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; @on&lt;/font&gt;                   &lt;br /&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt;exec&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; &lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#800000&quot;&gt;sp_trace_setevent&lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt; &lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt;@TraceID&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 146&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 4&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; @on&lt;/font&gt;                   &lt;br /&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt;exec&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; &lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#800000&quot;&gt;sp_trace_setevent&lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt; &lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt;@TraceID&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 146&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 12&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; @on&lt;/font&gt;                   &lt;br /&gt;                  &lt;br /&gt;&lt;/font&gt;&lt;font face=&quot;Lucida Console&quot;&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#008000&quot;&gt;-- Filter: Log only events for the provided @@spid&lt;/font&gt;                     &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt;if&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; @spId &lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;is&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; &lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;not&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; &lt;/font&gt;&lt;/font&gt;&lt;font face=&quot;Lucida Console&quot;&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;null&lt;/font&gt;                     &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;font color=&quot;#000000&quot;&gt;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt;exec&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; &lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#800000&quot;&gt;sp_trace_setfilter&lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt; &lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt;@TraceID&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 12&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 0&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 0&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; @spID&lt;/font&gt;                   &lt;br /&gt;                  &lt;br /&gt;&lt;/font&gt;&lt;font face=&quot;Lucida Console&quot;&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#008000&quot;&gt;-- Set the trace status to start&lt;/font&gt;                     &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt;exec&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; &lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#800000&quot;&gt;sp_trace_setstatus&lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt; &lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt;@TraceID&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 1&lt;/font&gt;                   &lt;br /&gt;                  &lt;br /&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt;goto&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; finish&lt;/font&gt;                   &lt;br /&gt;                  &lt;br /&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt;error:&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; &lt;/font&gt;                  &lt;br /&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt;select&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; ErrorCode&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;=&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt;@rc&lt;/font&gt;                   &lt;br /&gt;                  &lt;br /&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;font-family: ; color: ; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes&quot;&gt;&lt;font color=&quot;#0000ff&quot; face=&quot;Lucida Console&quot;&gt;finish:                  &lt;br /&gt;end&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;span style=&quot;font-family: ; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-no-proof: yes&quot;&gt;&lt;font face=&quot;Lucida Console&quot;&gt;&lt;font style=&quot;font-size: 10pt&quot;&gt;&lt;font color=&quot;#000000&quot;&gt; &lt;/font&gt;                  &lt;br /&gt;&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font style=&quot;font-size: 10pt&quot; color=&quot;#0000ff&quot;&gt;go&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;mso-ansi-language: en-us&quot; lang=&quot;EN-US&quot;&gt;&lt;/span&gt;&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;Some annotations:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;For the parameters, see the comments. &lt;/li&gt;    &lt;li&gt;Don&#039;t specify a filename extension for the trace file. .TRC will be added automatically. &lt;/li&gt;    &lt;li&gt;Ensure that the output file does not already exist. Otherwise you&#039;ll get an error. &lt;/li&gt;    &lt;li&gt;Very often I replace the code for starting and stopping the trace inside &quot;interesting code&quot; inside a stored procedure. That is, I&#039;m wrapping some more or less awkward code by starting and stopping a trace like this: &lt;/li&gt; &lt;/ul&gt;  &lt;table style=&quot;border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8db3e2; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8db3e2; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102&quot; class=&quot;MsoTableGrid&quot; border=&quot;1&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;&gt;&lt;tbody&gt;     &lt;tr style=&quot;mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes&quot;&gt;       &lt;td style=&quot;border-bottom: #8db3e2 1pt dashed; border-left: #8db3e2 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; border-top: #8db3e2 1pt dashed; border-right: #8db3e2 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102&quot; valign=&quot;top&quot; width=&quot;905&quot;&gt;         &lt;p style=&quot;line-height: normal; margin: 6pt 0in&quot; class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: ; color: ; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-ansi-language: en-us; mso-no-proof: yes&quot; lang=&quot;EN-US&quot;&gt;&lt;font color=&quot;#0000ff&quot; face=&quot;Lucida Console&quot;&gt;&lt;font style=&quot;font-size: 10pt&quot;&gt;declare&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;font-family: ; mso-bidi-font-family: &amp;#39;Times New Roman&amp;#39;; mso-ansi-language: en-us; mso-no-proof: yes&quot; lang=&quot;EN-US&quot;&gt;&lt;font style=&quot;font-size: 10pt&quot;&gt;&lt;font color=&quot;#000000&quot; face=&quot;Lucida Console&quot;&gt; @traceID &lt;/font&gt;&lt;font face=&quot;Lucida Console&quot;&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt;int                      &lt;br /&gt;exec&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; dbo&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;.&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt;configureServerSideTrace&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt; &lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt;@traceStatus &lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;=&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;font face=&quot;Lucida Console&quot;&gt;&lt;font color=&quot;#000000&quot;&gt; 1                    &lt;br /&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt;@traceID &lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;=&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; @traceID &lt;/font&gt;&lt;/font&gt;&lt;font face=&quot;Lucida Console&quot;&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt;output&lt;/font&gt;                     &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;font color=&quot;#000000&quot;&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt;@maxFileSize &lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;=&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;font face=&quot;Lucida Console&quot;&gt;&lt;font color=&quot;#000000&quot;&gt; 10000                    &lt;br /&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt;@traceFileName &lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;=&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; &lt;/font&gt;&lt;/font&gt;&lt;font face=&quot;Lucida Console&quot;&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#ff0000&quot;&gt;N&#039;e:\MyTrace\Test&#039;&lt;/font&gt;                     &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;font color=&quot;#000000&quot;&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt;@spId &lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;=&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; &lt;/font&gt;&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font face=&quot;Lucida Console&quot;&gt;&lt;font color=&quot;#ff00ff&quot;&gt;@@spid&lt;/font&gt;                     &lt;br /&gt;                    &lt;br /&gt;&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;font face=&quot;Lucida Console&quot;&gt;&lt;font style=&quot;font-size: 10pt&quot;&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#008000&quot;&gt;--                      &lt;br /&gt;-- Code of interest                       &lt;br /&gt;--&lt;/font&gt;                     &lt;br /&gt;                    &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt;exec&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; dbo&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;.&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt;configureServerSideTrace&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#0000ff&quot;&gt; &lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt;@traceStatus &lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;=&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; 0&lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;,&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; @traceID &lt;/font&gt;&lt;span style=&quot;color: &quot;&gt;&lt;font color=&quot;#808080&quot;&gt;=&lt;/font&gt;&lt;/span&gt;&lt;font color=&quot;#000000&quot;&gt; @traceID&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;mso-ansi-language: en-us&quot; lang=&quot;EN-US&quot;&gt;&lt;/span&gt;&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;Cheers.&lt;/p&gt;</description>
			<content:encoded><![CDATA[<p>When I'm after SQL Server performance&#160; problems, SQL Server Profiler is still my number one tool. Allthough I know that extended events provide a mor lightweight solution, those are still a bit cumbersome to use (but I've seen that we can expect some improvements with SQL Server 2012).</p>  <p>When I'm using profiler to isolate performance issues, I try to configure server side traces, whenever possible. Fortunately, SQL Server Profiler will help you creating a script for a server side trace (File/Export/Script Trace Definition), so you don't have to figure out all the event- and column-codes. Very good!</p>  <p>As I was doing the same configuration again and again, I decided to separate the TSQL code for the configuration inside a stored procedure.</p>  <p>And here comes dbo.configureServerSideTrace:</p>  <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8db3e2; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8db3e2; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0" width="1315"><tbody>     <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes">       <td style="border-bottom: #8db3e2 1pt dashed; border-left: #8db3e2 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; border-top: #8db3e2 1pt dashed; border-right: #8db3e2 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="1313">         <p style="line-height: normal; margin: 6pt 0in" class="MsoNormal"><span style="font-family: ; color: ; mso-bidi-font-family: &#39;Times New Roman&#39;; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><font color="#0000ff" face="Lucida Console"><font style="font-size: 10pt">if</font></font></span><font style="font-size: 10pt"><span style="font-family: ; mso-bidi-font-family: &#39;Times New Roman&#39;; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><font face="Lucida Console"><font color="#000000"> </font><span style="color: "><font color="#ff00ff">object_id</font></span><span style="color: "><font color="#808080">(</font></span><span style="color: "><font color="#ff0000">'dbo.configureServerSideTrace'</font></span><span style="color: "><font color="#808080">,</font></span><font color="#000000"> </font><span style="color: "><font color="#ff0000">'P'</font></span><span style="color: "><font color="#808080">)</font></span><font color="#000000"> </font><span style="color: "><font color="#808080">is</font></span><font color="#000000"> </font><span style="color: "><font color="#808080">not</font></span><font color="#000000"> </font></font><font face="Lucida Console"><span style="color: "><font color="#808080">null</font>                     <br /></span><span style="mso-spacerun: yes"><font color="#000000">&#160; </font></span><span style="color: "><font color="#0000ff">drop</font></span><font color="#000000"> </font><span style="color: "><font color="#0000ff">procedure</font></span><font color="#000000"> dbo</font><span style="color: "><font color="#808080">.</font></span><font color="#000000">configureServerSideTrace</font>                   <br /></font><span style="color: "><font face="Lucida Console"><font color="#0000ff">go</font>                     <br />                    <br /></font></span><font face="Lucida Console"><span style="color: "><font color="#008000">-- Example for:                      <br />-- Start Trace                       <br />--<span style="mso-spacerun: yes">&#160;&#160; </span>declare @traceID int                       <br />--<span style="mso-spacerun: yes">&#160;&#160; </span>exec dbo.configureServerSideTrace @traceStatus = 1                       <br />--<span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span>,@traceID = @traceID output                       <br />--<span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span>,@maxFileSize = 10000                       <br />--<span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span>,@traceFileName = N'e:\VMITrace\Undo'                       <br />--<span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span>,@spId = @@spid                       <br />--                       <br />-- End Trace                       <br />--<span style="mso-spacerun: yes">&#160;&#160; </span>exec dbo.configureServerSideTrace @traceStatus = 0, @traceID = @traceID</font>                     <br />                    <br />                    <br /></span><span style="color: "><font color="#0000ff">create</font></span><font color="#000000"> </font><span style="color: "><font color="#0000ff">procedure</font></span><font color="#000000"> dbo</font><span style="color: "><font color="#808080">.</font></span><font color="#000000">configureServerSideTrace</font>                   <br /><span style="color: "><span style="mso-spacerun: yes"><font color="#0000ff">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </font></span></span><span style="color: "><font color="#808080">(</font></span><font color="#000000">@traceStatus<span style="mso-spacerun: yes">&#160;&#160; </span></font><span style="color: "><font color="#0000ff">bit</font></span><span style="mso-spacerun: yes"><font color="#000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </font></span></font><font face="Lucida Console"><span style="color: "><font color="#008000">-- 1 =&gt; Start Trace</font>                     <br /></span><span style="mso-spacerun: yes"><font color="#000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </font></span></font><font face="Lucida Console"><span style="color: "><font color="#008000">-- 0 =&gt; Stop Trace</font>                     <br /></span><span style="mso-spacerun: yes"><font color="#000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </font></span><span style="color: "><font color="#808080">,</font></span><font color="#000000">@traceID<span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160; </span></font><span style="color: "><font color="#0000ff">int</font></span><font color="#000000"> </font><span style="color: "><font color="#0000ff">output</font></span><span style="mso-spacerun: yes"><font color="#000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </font></span></font><font face="Lucida Console"><span style="color: "><font color="#008000">-- If the Trace is started, this param will return the TraceID</font>                     <br /></span><span style="mso-spacerun: yes"><font color="#000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </font></span></font><font face="Lucida Console"><span style="color: "><font color="#008000">-- For stopping the trace, the param has to be provided</font>                     <br /></span><span style="mso-spacerun: yes"><font color="#000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </font></span><span style="color: "><font color="#808080">,</font></span><font color="#000000">@spId<span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span></font><span style="color: "><font color="#0000ff">int</font></span><span style="mso-spacerun: yes"><font color="#000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </font></span><span style="color: "><font color="#808080">=</font></span><font color="#000000"> </font><span style="color: "><font color="#808080">null</font></span><font color="#000000"> </font></font><font face="Lucida Console"><span style="color: "><font color="#008000">-- provide the @@spid, if you want to filter only events for this conection</font>                     <br /></span><span style="mso-spacerun: yes"><font color="#000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </font></span></font><font face="Lucida Console"><span style="color: "><font color="#008000">-- Optional. If not provided =&gt; no filter. Not needed for stopping the trace</font>                     <br /></span><font color="#000000"><span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="mso-spacerun: yes">&#160;&#160; </span></font><span style="color: "><font color="#808080">,</font></span><font color="#000000">@maxFileSize<span style="mso-spacerun: yes">&#160;&#160; </span></font><span style="color: "><font color="#0000ff">bigint</font></span><span style="mso-spacerun: yes"><font color="#000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160; </font></span><span style="color: "><font color="#808080">=</font></span><font color="#000000"> 5000 </font></font><font face="Lucida Console"><span style="color: "><font color="#008000">-- Maximum Trace File Size in Megabyte. Trace will be stopped, if the filesize is reached.</font>                     <br /></span><span style="mso-spacerun: yes"><font color="#000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </font></span><span style="color: "><font color="#808080">,</font></span><font color="#000000">@traceFileName </font><span style="color: "><font color="#0000ff">nvarchar</font></span><span style="color: "><font color="#808080">(</font></span><font color="#000000">200</font><span style="color: "><font color="#808080">)</font></span><font color="#000000"> </font><span style="color: "><font color="#808080">=</font></span><font color="#000000"> </font><span style="color: "><font color="#808080">null</font></span><font color="#000000"> </font></font><font face="Lucida Console"><span style="color: "><font color="#008000">-- Name of the trace file (server side!)</font>                     <br /></span><font color="#000000"><span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span></font></font><font face="Lucida Console"><span style="color: "><font color="#008000">-- Optional. Not neded for stoping the trace</font>                     <br /></span><span style="mso-spacerun: yes"><font color="#000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </font></span></font><font face="Lucida Console"><span style="color: "><font color="#008000">-- Attention! If the file already exists, the SP will yield an error</font>                     <br /></span><font color="#000000"><span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span></font></font><font face="Lucida Console"><span style="color: "><font color="#008000">-- and no trace is started.</font>                     <br /></span><span style="mso-spacerun: yes"><font color="#000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </font></span><span style="color: "><font color="#808080">)</font></span><font color="#000000"> </font></font><font face="Lucida Console"><span style="color: "><font color="#0000ff">as                      <br />begin                       <br />                      <br />if </font></span><span style="color: "><font color="#808080">(</font></span><font color="#000000">@traceStatus </font><span style="color: "><font color="#808080">=</font></span><font color="#000000"> 0</font></font><span style="color: "><font face="Lucida Console"><font color="#808080">)</font>                     <br /></font></span><font face="Lucida Console"><span style="color: "><font color="#0000ff">begin</font>                     <br /></span><span style="mso-spacerun: yes"><font color="#000000">&#160;&#160; </font></span><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setstatus</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span></font><font face="Lucida Console"><font color="#000000"> 0                    <br /><span style="mso-spacerun: yes">&#160;&#160; </span></font><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setstatus</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span></font><font face="Lucida Console"><font color="#000000"> 2                    <br /><span style="mso-spacerun: yes">&#160;&#160; </span></font><span style="color: "><font color="#0000ff">return</font></span></font><span style="color: "><font face="Lucida Console"><font color="#808080">;</font>                     <br /></font></span><span style="color: "><font face="Lucida Console"><font color="#0000ff">end</font>                     <br />                    <br /></font></span><font face="Lucida Console"><span style="color: "><font color="#008000">-- Create a Queue</font>                     <br /></span><span style="color: "><font color="#0000ff">declare</font></span><font color="#000000"> @rc </font></font><font face="Lucida Console"><span style="color: "><font color="#0000ff">int                      <br />                      <br />exec</font></span><font color="#000000"> @rc </font><span style="color: "><font color="#808080">=</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_create</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID </font><span style="color: "><font color="#0000ff">output</font></span><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 0</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @traceFileName</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @maxfilesize</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> </font><span style="color: "><font color="#808080">NULL</font></span><font color="#000000"> </font>                  <br /><span style="color: "><font color="#0000ff">if </font></span><span style="color: "><font color="#808080">(</font></span><font color="#000000">@rc </font><span style="color: "><font color="#808080">!=</font></span><font color="#000000"> 0</font><span style="color: "><font color="#808080">)</font></span><font color="#000000"> </font><span style="color: "><font color="#0000ff">goto</font></span><font color="#000000"> error</font>                   <br />                  <br /></font><font face="Lucida Console"><span style="color: "><font color="#008000">-- Set the events</font>                     <br /></span><span style="color: "><font color="#0000ff">declare</font></span><font color="#000000"> @on </font></font><font face="Lucida Console"><span style="color: "><font color="#0000ff">bit                      <br />set</font></span><font color="#000000"> @on </font><span style="color: "><font color="#808080">=</font></span><font color="#000000"> 1</font>                   <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 43</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 15</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font>                   <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 43</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 48</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font>                   <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 43</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 1</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font>                   <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 43</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 34</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font>                   <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 43</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 35</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font>                   <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 43</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 51</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font>                   <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 43</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 4</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font>                   <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 43</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 12</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font>                   <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 43</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 13</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font>                   <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 43</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 14</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font>                   <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 43</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 22</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font>                   <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 42</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 1</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font>                   <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 42</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 14</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font>                   <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 42</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 22</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font>                   <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 42</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 34</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font>                   <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 42</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 35</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font>                   <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 42</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 51</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font>                   <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 42</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 4</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font>                   <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 42</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 12</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font>                   <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 45</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 16</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font>                   <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 45</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 48</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font>                   <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 45</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 1</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font>                   <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 45</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 17</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font>                   <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 45</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 18</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font>                   <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 45</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 34</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font>                   <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 45</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 35</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font>                   <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 45</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 51</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font>                   <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 45</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 4</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font>                   <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 45</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 12</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font>                   <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 45</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 13</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font>                   <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 45</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 14</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font>                   <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 45</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 22</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font>                   <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 45</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 15</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font>                   <br /></font><font face="Lucida Console"><span style="color: "><font color="#008000">-- XML Statistics Profile</font>                     <br /></span><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 146</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 1</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font>                   <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 146</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 51</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font>                   <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 146</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 4</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font>                   <br /><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setevent</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 146</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 12</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @on</font>                   <br />                  <br /></font><font face="Lucida Console"><span style="color: "><font color="#008000">-- Filter: Log only events for the provided @@spid</font>                     <br /></span><span style="color: "><font color="#0000ff">if</font></span><font color="#000000"> @spId </font><span style="color: "><font color="#808080">is</font></span><font color="#000000"> </font><span style="color: "><font color="#808080">not</font></span><font color="#000000"> </font></font><font face="Lucida Console"><span style="color: "><font color="#808080">null</font>                     <br /></span><span style="mso-spacerun: yes"><font color="#000000">&#160; </font></span><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setfilter</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 12</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 0</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 0</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @spID</font>                   <br />                  <br /></font><font face="Lucida Console"><span style="color: "><font color="#008000">-- Set the trace status to start</font>                     <br /></span><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> </font><span style="color: "><font color="#800000">sp_trace_setstatus</font></span><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@TraceID</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> 1</font>                   <br />                  <br /><span style="color: "><font color="#0000ff">goto</font></span><font color="#000000"> finish</font>                   <br />                  <br /><span style="color: "><font color="#0000ff">error:</font></span><font color="#000000"> </font>                  <br /><span style="color: "><font color="#0000ff">select</font></span><font color="#000000"> ErrorCode</font><span style="color: "><font color="#808080">=</font></span><font color="#000000">@rc</font>                   <br />                  <br /></font></span><span style="font-family: ; color: ; mso-bidi-font-family: &#39;Times New Roman&#39;; mso-no-proof: yes"><font color="#0000ff" face="Lucida Console">finish:                  <br />end</font></span></font><span style="font-family: ; mso-bidi-font-family: &#39;Times New Roman&#39;; mso-no-proof: yes"><font face="Lucida Console"><font style="font-size: 10pt"><font color="#000000"> </font>                  <br /></font><span style="color: "><font style="font-size: 10pt" color="#0000ff">go</font></span></font></span><span style="mso-ansi-language: en-us" lang="EN-US"></span></p>       </td>     </tr>   </tbody></table>  <p>Some annotations:</p>  <ul>   <li>For the parameters, see the comments. </li>    <li>Don't specify a filename extension for the trace file. .TRC will be added automatically. </li>    <li>Ensure that the output file does not already exist. Otherwise you'll get an error. </li>    <li>Very often I replace the code for starting and stopping the trace inside "interesting code" inside a stored procedure. That is, I'm wrapping some more or less awkward code by starting and stopping a trace like this: </li> </ul>  <table style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8db3e2; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8db3e2; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0"><tbody>     <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes">       <td style="border-bottom: #8db3e2 1pt dashed; border-left: #8db3e2 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; border-top: #8db3e2 1pt dashed; border-right: #8db3e2 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" valign="top" width="905">         <p style="line-height: normal; margin: 6pt 0in" class="MsoNormal"><span style="font-family: ; color: ; mso-bidi-font-family: &#39;Times New Roman&#39;; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><font color="#0000ff" face="Lucida Console"><font style="font-size: 10pt">declare</font></font></span><span style="font-family: ; mso-bidi-font-family: &#39;Times New Roman&#39;; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><font style="font-size: 10pt"><font color="#000000" face="Lucida Console"> @traceID </font><font face="Lucida Console"><span style="color: "><font color="#0000ff">int                      <br />exec</font></span><font color="#000000"> dbo</font><span style="color: "><font color="#808080">.</font></span><font color="#000000">configureServerSideTrace</font><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@traceStatus </font><span style="color: "><font color="#808080">=</font></span></font><font face="Lucida Console"><font color="#000000"> 1                    <br /><span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span></font><span style="color: "><font color="#808080">,</font></span><font color="#000000">@traceID </font><span style="color: "><font color="#808080">=</font></span><font color="#000000"> @traceID </font></font><font face="Lucida Console"><span style="color: "><font color="#0000ff">output</font>                     <br /></span><span style="mso-spacerun: yes"><font color="#000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </font></span><span style="color: "><font color="#808080">,</font></span><font color="#000000">@maxFileSize </font><span style="color: "><font color="#808080">=</font></span></font><font face="Lucida Console"><font color="#000000"> 10000                    <br /><span style="mso-spacerun: yes">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span></font><span style="color: "><font color="#808080">,</font></span><font color="#000000">@traceFileName </font><span style="color: "><font color="#808080">=</font></span><font color="#000000"> </font></font><font face="Lucida Console"><span style="color: "><font color="#ff0000">N'e:\MyTrace\Test'</font>                     <br /></span><span style="mso-spacerun: yes"><font color="#000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </font></span><span style="color: "><font color="#808080">,</font></span><font color="#000000">@spId </font><span style="color: "><font color="#808080">=</font></span><font color="#000000"> </font></font><span style="color: "><font face="Lucida Console"><font color="#ff00ff">@@spid</font>                     <br />                    <br /></font></span></font><font face="Lucida Console"><font style="font-size: 10pt"><span style="color: "><font color="#008000">--                      <br />-- Code of interest                       <br />--</font>                     <br />                    <br /></span><span style="color: "><font color="#0000ff">exec</font></span><font color="#000000"> dbo</font><span style="color: "><font color="#808080">.</font></span><font color="#000000">configureServerSideTrace</font><span style="color: "><font color="#0000ff"> </font></span><font color="#000000">@traceStatus </font><span style="color: "><font color="#808080">=</font></span><font color="#000000"> 0</font><span style="color: "><font color="#808080">,</font></span><font color="#000000"> @traceID </font><span style="color: "><font color="#808080">=</font></span><font color="#000000"> @traceID</font></font></font></span><span style="mso-ansi-language: en-us" lang="EN-US"></span></p>       </td>     </tr>   </tbody></table>  <p>Cheers.</p>]]></content:encoded>
								<comments>https://www.insidesql.org/blogs/holgerschmeling/2011/11/01/configuring-a-server-side-trace#comments</comments>
			<wfw:commentRss>https://www.insidesql.org/blogs/holgerschmeling/?tempskin=_rss2&#38;disp=comments&#38;p=3044</wfw:commentRss>
		</item>
				<item>
			<title>Calculating SQL Server Data Compression Savings</title>
			<link>https://www.insidesql.org/blogs/holgerschmeling/2011/02/27/calculating-sql-server-data-compression-savings</link>
			<pubDate>Sun, 27 Feb 2011 14:59:46 +0000</pubDate>			<dc:creator>Holger Schmeling</dc:creator>
			<category domain="main">SQL Server Administration</category>
<category domain="alt">SQL Server Performance</category>			<guid isPermaLink="false">2706@https://www.insidesql.org/blogs/</guid>
						<description>&lt;p&gt;SQL Server 2008 Enterprise edition comes with an opportunity for storing table or index data in a compressed format which may save huge amount of storage space and - much more important - IO requests and buffer pool utilization. There&#039;s two different options for data compression, namely Row and Page level compression. This blog post is not concerned with how these two work internally and will also not explain the differences between the two. If you like to know more about this, you find much of useful information on the internet - including links to further articles (e.g. &lt;a href=&quot;http://blogs.msdn.com/b/sqlserverstorageengine/archive/2007/11/12/types-of-data-compression-in-sql-server-2008.aspx&quot;&gt;here&lt;/a&gt;, &lt;a href=&quot;http://www.sqlskills.com/blogs/kimberly/post/SQL-Server-2005-and-2008-Compression.aspx&quot;&gt;here&lt;/a&gt;, and &lt;a href=&quot;http://blogs.msdn.com/b/sqlserverstorageengine/archive/2009/08/16/update-on-data-compression-in-sql-server-2008-rtm.aspx&quot;&gt;here&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;Whether compression is worth or not isn&#039;t an easy question to answer. One aspect that has to be taken into account is certainly the amount of storage that may be saved by storing a distinct table or index in any of the two compressed formats. SSMS offers a Data Compression Wizard than can provide storage-saving estimates for row or page level compression. From the context menu for a table or index just open Storage/Manage Compression. In the Combo box at the top select the compression type (Row or Page) and press the Calculate Button at the bottom. Here&#039;s a sample of a calculated saving for an index:&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;/blogs/media/blogs/holgerschmeling/windows-live-writer/44bf6e1fbe53_9687/image_4.png&quot;&gt;&lt;img style=&quot;background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px&quot; title=&quot;image&quot; src=&quot;/blogs/media/blogs/holgerschmeling/windows-live-writer/44bf6e1fbe53_9687/image_thumb_1.png&quot; border=&quot;0&quot; alt=&quot;image&quot; width=&quot;600&quot; height=&quot;501&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Unfortunately, SSMS does not offer an option for calculating estimated savings for more than one table or index at once. If you, let&#039;s say, would like to know the estimated storage savings of page level compression for you largest 10 tables, there&#039;s no GUI support in SSMS that will assist you in finding an answer. This is, where the stored procedure &lt;em&gt;sp_estimate_data_compression_savings&lt;/em&gt; comes in handy. This procedure - as you may have guessed from its name - provides estimated savings for row or page level compression for any table or index. You have to provide the table or index as a parameter to the procedure. In other words: The procedure will only calculate the estimations for one table or index at a time. If you want to retrieve the calculations of more than one table or index as a result set, there&#039;s some more work to do, since the procedure has to be invoked multiple times. Here&#039;s a script that calculates the estimated savings of page level compression for the database in context.&lt;/p&gt;
&lt;table class=&quot;MsoTableGrid&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8db3e2; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8db3e2; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102&quot; border=&quot;1&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;&gt;
&lt;tbody&gt;
&lt;tr style=&quot;mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes&quot;&gt;
&lt;td style=&quot;border-bottom: #8db3e2 1pt dashed; border-left: #8db3e2 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; border-top: #8db3e2 1pt dashed; border-right: #8db3e2 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102&quot; width=&quot;905&quot; valign=&quot;top&quot;&gt;
&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none&quot;&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;font-family: ; mso-bidi-font-family: &#039;Times New Roman&#039;; mso-ansi-language: en-us; mso-no-proof: yes&quot; lang=&quot;EN-US&quot;&gt;&lt;span style=&quot;color: #008000;&quot;&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;-- Determine the estimated impact of compression                    &lt;br /&gt;-- NOTE: This script is only for SQL Server Enterprise and Developer edition.&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt; &lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;&lt;span style=&quot;font-family: ; mso-bidi-font-family: &#039;Times New Roman&#039;; mso-ansi-language: en-us; mso-no-proof: yes&quot; lang=&quot;EN-US&quot;&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;set&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;&lt;span style=&quot;font-family: ; mso-bidi-font-family: &#039;Times New Roman&#039;; mso-ansi-language: en-us; mso-no-proof: yes&quot; lang=&quot;EN-US&quot;&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;nocount&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;on&lt;/span&gt; &lt;br /&gt; &lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;-- We create a temp table for the result&lt;/span&gt; &lt;br /&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;if &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #ff00ff;&quot;&gt;object_id&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;tempdb..#comp&#039;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;,&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;U&#039;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;is&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;not&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;null)&lt;/span&gt; &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;drop&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;table&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; #comp&lt;/span&gt; &lt;br /&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;go&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;/span&gt; &lt;br /&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;create&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;table&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; #comp&lt;/span&gt; &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;(&lt;/span&gt; &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #ff00ff;&quot;&gt;object_name&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;sysname&lt;/span&gt; &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;,&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #ff00ff;&quot;&gt;schema_name&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;sysname&lt;/span&gt; &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;,&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;index_id &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;int&lt;/span&gt; &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;,&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;partition_number &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;int&lt;/span&gt; &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;,&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;[size_with_current_compression_setting (KB)] &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;bigint&lt;/span&gt; &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;,&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;[size_with_requested_compression_setting (KB)] &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;bigint&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;br /&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;,&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;[sample_size_with_current_compression_setting (KB)] &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;bigint&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;br /&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;,&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;[sample_size_with_requested_compression_setting (KB)] &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;bigint&lt;/span&gt; &lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;color: #808080;&quot;&gt;)&lt;/span&gt; &lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;go&lt;/span&gt; &lt;br /&gt; &lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;-- Calculate estimated impact of page level compression for all                      &lt;br /&gt;-- user-tables and indexes in all schemas.                       &lt;br /&gt;-- NOTE:                       &lt;br /&gt;--&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;1) To get the estimated impact of row level compression change the last parameter                       &lt;br /&gt;--&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;of sp_estimate_data_compression_savings to &#039;row&#039; instead.                       &lt;br /&gt;--&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;2) We don&#039;t care about partitioning here. If this is important for you,                       &lt;br /&gt;--&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;you have to modify forth parameter of sp_estimate_data_compression_savings.                       &lt;br /&gt;--&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;Please refer to BOL.&lt;/span&gt; &lt;br /&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;declare&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; @cmd &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;nvarchar&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #ff00ff;&quot;&gt;max&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;)&lt;/span&gt; &lt;br /&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;set&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; @cmd &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;=&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;&#039;&lt;/span&gt; &lt;br /&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;select&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; @cmd &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;=&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; @cmd                    &lt;br /&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;+&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;;insert #comp exec sp_estimate_data_compression_savings &#039;&#039;&#039;&lt;/span&gt; &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: ; mso-bidi-font-family: &#039;Times New Roman&#039;; mso-no-proof: yes&quot;&gt;&lt;span style=&quot;font-family: Lucida Console; color: #808080;&quot;&gt;+&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: ; mso-bidi-font-family: &#039;Times New Roman&#039;; mso-no-proof: yes&quot;&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #ff00ff;&quot;&gt;schema_name&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #ff00ff;&quot;&gt;schema_id&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;)+&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;&#039;&#039;,&#039;&#039;&#039;&lt;/span&gt; &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: ; mso-bidi-font-family: &#039;Times New Roman&#039;; mso-ansi-language: en-us; mso-no-proof: yes&quot; lang=&quot;EN-US&quot;&gt;&lt;span style=&quot;font-family: Lucida Console; color: #808080;&quot;&gt;+&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: ; mso-bidi-font-family: &#039;Times New Roman&#039;; mso-ansi-language: en-us; mso-no-proof: yes&quot; lang=&quot;EN-US&quot;&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; name &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;+&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;&#039;&#039;,null, null, &#039;&#039;page&#039;&#039;&#039;&lt;/span&gt; &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;from&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;sys&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;tables&lt;/span&gt; &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;where&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #ff00ff;&quot;&gt;objectproperty&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #ff00ff;&quot;&gt;object_id&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;,&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;IsUserTable&#039;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;=&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; 1&lt;/span&gt; &lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;font-family: ; mso-bidi-font-family: &#039;Times New Roman&#039;; mso-no-proof: yes&quot;&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;exec &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: ; mso-bidi-font-family: &#039;Times New Roman&#039;; mso-no-proof: yes&quot;&gt;&lt;span style=&quot;color: #808080;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: ; mso-bidi-font-family: &#039;Times New Roman&#039;; mso-no-proof: yes&quot;&gt;&lt;span style=&quot;font-family: Lucida Console; color: #000000;&quot;&gt;@cmd&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;font-family: Lucida Console; color: #808080;&quot;&gt;)                    &lt;br /&gt; &lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: ; mso-bidi-font-family: &#039;Times New Roman&#039;; mso-ansi-language: en-us; mso-no-proof: yes&quot; lang=&quot;EN-US&quot;&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;color: #808080;&quot;&gt;;&lt;/span&gt; &lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;font-family: ; mso-bidi-font-family: &#039;Times New Roman&#039;; mso-ansi-language: en-us; mso-no-proof: yes&quot; lang=&quot;EN-US&quot;&gt;&lt;span style=&quot;color: #008000;&quot;&gt;-- Do some further calculations for a more meaningful result&lt;/span&gt; &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-family: ; mso-bidi-font-family: &#039;Times New Roman&#039;; mso-ansi-language: en-us; mso-no-proof: yes&quot; lang=&quot;EN-US&quot;&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;with&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: ; mso-bidi-font-family: &#039;Times New Roman&#039;; mso-ansi-language: en-us; mso-no-proof: yes&quot; lang=&quot;EN-US&quot;&gt;&lt;span style=&quot;font-family: Lucida Console; color: #000000;&quot;&gt; compressionSavings &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;as&lt;/span&gt; &lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;(&lt;/span&gt; &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;select&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #ff00ff;&quot;&gt;quotename&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #ff00ff;&quot;&gt;schema_name&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;+&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;.&#039;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;+&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #ff00ff;&quot;&gt;quotename&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #ff00ff;&quot;&gt;object_name&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;as&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; table_name                    &lt;br /&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;,&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt;index_id                    &lt;br /&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;,&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt;[size_with_current_compression_setting (KB)]                    &lt;br /&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;,&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt;[size_with_requested_compression_setting (KB)]                    &lt;br /&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;,&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #ff00ff;&quot;&gt;cast&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;case&lt;/span&gt; &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;when&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; [size_with_current_compression_setting (KB)] &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;=&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; 0 &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;then&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; 0                    &lt;br /&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;else&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; 100.0&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;*(&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;1.0&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;-&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt;1.0                    &lt;br /&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;*&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt;[size_with_requested_compression_setting (KB)]                    &lt;br /&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;/&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;[size_with_current_compression_setting (KB)]&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;)&lt;/span&gt; &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;end&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;as&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;decimal&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;6&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;,&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;2&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;))&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;as&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; [Estimated Savings (%)]                    &lt;br /&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;from&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; #comp&lt;/span&gt; &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;)&lt;/span&gt; &lt;br /&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;select&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; cs&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt;table_name                    &lt;br /&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;,&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #ff00ff;&quot;&gt;isnull&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;i&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;name&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;,&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; i&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;type_desc&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;as&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; index_name                    &lt;br /&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;,&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;cs&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt;[size_with_current_compression_setting (KB)]                    &lt;br /&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;,&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;cs&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt;[size_with_requested_compression_setting (KB)]                    &lt;br /&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;,&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;cs&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;[Estimated Savings (%)]&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span&gt; &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;from&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; compressionSavings &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;as&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; cs                    &lt;br /&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;left&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;outer&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;join&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;sys&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;indexes&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;as&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; i                    &lt;br /&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;on&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; i&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;index_id &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;=&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; cs&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt;index_id                    &lt;br /&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;and&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; i&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #ff00ff;&quot;&gt;object_id&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;=&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #ff00ff;&quot;&gt;object_id&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;cs&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;table_name&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;,&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;U&#039;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;)&lt;/span&gt; &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;order&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;by&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; cs&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;[Estimated Savings (%)] &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;desc&lt;/span&gt; &lt;br /&gt; &lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;color: #008000;&quot;&gt;-- Get rid of the temp table&lt;/span&gt; &lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: ; mso-bidi-font-family: &#039;Times New Roman&#039;; mso-no-proof: yes&quot;&gt;&lt;span style=&quot;font-family: Lucida Console; color: #0000ff;&quot;&gt;drop&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: ; mso-bidi-font-family: &#039;Times New Roman&#039;; mso-no-proof: yes&quot;&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;table&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; #comp&lt;/span&gt; &lt;br /&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;font-size: 11pt; color: #0000ff;&quot;&gt;go&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;The script calculates the impact of Page level compression but may easily be adapted to consider Row level compression instead. Please read the comments inside the script. Also, please notice that the script will only run on SQL Server Enterprise and Developer edition. All other editions don&#039;t provide the opportunity for data compression.&lt;/p&gt;
&lt;p&gt;Here&#039;s a partial result retrieved from running the script against the &lt;em&gt;AdventureWorksDW2008R2&lt;/em&gt; database.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;/blogs/media/blogs/holgerschmeling/windows-live-writer/44bf6e1fbe53_9687/image_2.png&quot;&gt;&lt;img style=&quot;background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px&quot; title=&quot;image&quot; src=&quot;/blogs/media/blogs/holgerschmeling/windows-live-writer/44bf6e1fbe53_9687/image_thumb.png&quot; border=&quot;0&quot; alt=&quot;image&quot; width=&quot;955&quot; height=&quot;186&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;If you execute the script, please be aware that it may produce some extensive I/O. Running the script against your production database at business hours wouldn&#039;t be a very good idea therefore.&lt;/p&gt;</description>
			<content:encoded><![CDATA[<p>SQL Server 2008 Enterprise edition comes with an opportunity for storing table or index data in a compressed format which may save huge amount of storage space and - much more important - IO requests and buffer pool utilization. There's two different options for data compression, namely Row and Page level compression. This blog post is not concerned with how these two work internally and will also not explain the differences between the two. If you like to know more about this, you find much of useful information on the internet - including links to further articles (e.g. <a href="http://blogs.msdn.com/b/sqlserverstorageengine/archive/2007/11/12/types-of-data-compression-in-sql-server-2008.aspx">here</a>, <a href="http://www.sqlskills.com/blogs/kimberly/post/SQL-Server-2005-and-2008-Compression.aspx">here</a>, and <a href="http://blogs.msdn.com/b/sqlserverstorageengine/archive/2009/08/16/update-on-data-compression-in-sql-server-2008-rtm.aspx">here</a>).</p>
<p>Whether compression is worth or not isn't an easy question to answer. One aspect that has to be taken into account is certainly the amount of storage that may be saved by storing a distinct table or index in any of the two compressed formats. SSMS offers a Data Compression Wizard than can provide storage-saving estimates for row or page level compression. From the context menu for a table or index just open Storage/Manage Compression. In the Combo box at the top select the compression type (Row or Page) and press the Calculate Button at the bottom. Here's a sample of a calculated saving for an index:</p>
<p><a href="/blogs/media/blogs/holgerschmeling/windows-live-writer/44bf6e1fbe53_9687/image_4.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" src="/blogs/media/blogs/holgerschmeling/windows-live-writer/44bf6e1fbe53_9687/image_thumb_1.png" border="0" alt="image" width="600" height="501" /></a></p>
<p>Unfortunately, SSMS does not offer an option for calculating estimated savings for more than one table or index at once. If you, let's say, would like to know the estimated storage savings of page level compression for you largest 10 tables, there's no GUI support in SSMS that will assist you in finding an answer. This is, where the stored procedure <em>sp_estimate_data_compression_savings</em> comes in handy. This procedure - as you may have guessed from its name - provides estimated savings for row or page level compression for any table or index. You have to provide the table or index as a parameter to the procedure. In other words: The procedure will only calculate the estimations for one table or index at a time. If you want to retrieve the calculations of more than one table or index as a result set, there's some more work to do, since the procedure has to be invoked multiple times. Here's a script that calculates the estimated savings of page level compression for the database in context.</p>
<table class="MsoTableGrid" style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8db3e2; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8db3e2; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes">
<td style="border-bottom: #8db3e2 1pt dashed; border-left: #8db3e2 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; border-top: #8db3e2 1pt dashed; border-right: #8db3e2 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" width="905" valign="top">
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none"><span style="font-family: Lucida Console;"><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><span style="color: #008000;"><span style="font-size: 11pt;">-- Determine the estimated impact of compression                    <br />-- NOTE: This script is only for SQL Server Enterprise and Developer edition.</span></span><span style="font-size: 11pt;"> <br /></span></span><span style="font-size: 11pt;"><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><span style="color: #0000ff;">set</span></span></span></span><span style="font-size: 11pt;"><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><span style="font-family: Lucida Console;"><span style="color: #000000;"> </span><span><span style="color: #0000ff;">nocount</span></span><span style="color: #000000;"> </span></span><span><span style="font-family: Lucida Console;"><span style="color: #0000ff;">on</span> <br /> <br /></span></span><span style="font-family: Lucida Console;"><span><span style="color: #008000;">-- We create a temp table for the result</span> <br /></span><span><span style="color: #0000ff;">if </span></span><span><span style="color: #808080;">(</span></span><span><span style="color: #ff00ff;">object_id</span></span><span><span style="color: #808080;">(</span></span><span><span style="color: #ff0000;">'tempdb..#comp'</span></span><span><span style="color: #808080;">,</span></span><span style="color: #000000;"> </span><span><span style="color: #ff0000;">'U'</span></span><span><span style="color: #808080;">)</span></span><span style="color: #000000;"> </span><span><span style="color: #808080;">is</span></span><span style="color: #000000;"> </span><span><span style="color: #808080;">not</span></span><span style="color: #000000;"> </span></span><span style="font-family: Lucida Console;"><span><span style="color: #808080;">null)</span> <br /></span><span style="mso-spacerun: yes"><span style="color: #000000;"> </span></span><span><span style="color: #0000ff;">drop</span></span><span style="color: #000000;"> </span><span><span style="color: #0000ff;">table</span></span><span style="color: #000000;"> #comp</span> <br /><span><span style="color: #0000ff;">go</span></span><span style="mso-spacerun: yes"><span style="color: #000000;"> </span></span> <br /><span><span style="color: #0000ff;">create</span></span><span style="color: #000000;"> </span><span><span style="color: #0000ff;">table</span></span><span style="color: #000000;"> #comp</span> <br /></span><span style="font-family: Lucida Console;"><span><span style="color: #808080;">(</span> <br /></span><span style="mso-spacerun: yes"><span style="color: #000000;"> </span></span><span><span style="color: #ff00ff;">object_name</span></span><span style="color: #000000;"> </span></span><span style="font-family: Lucida Console;"><span><span style="color: #0000ff;">sysname</span> <br /></span><span style="mso-spacerun: yes"><span style="color: #000000;"> </span></span><span><span style="color: #808080;">,</span></span><span><span style="color: #ff00ff;">schema_name</span></span><span style="color: #000000;"> </span></span><span style="font-family: Lucida Console;"><span><span style="color: #0000ff;">sysname</span> <br /></span><span style="mso-spacerun: yes"><span style="color: #000000;"> </span></span><span><span style="color: #808080;">,</span></span><span style="color: #000000;">index_id </span></span><span style="font-family: Lucida Console;"><span><span style="color: #0000ff;">int</span> <br /></span><span style="mso-spacerun: yes"><span style="color: #000000;"> </span></span><span><span style="color: #808080;">,</span></span><span style="color: #000000;">partition_number </span></span><span style="font-family: Lucida Console;"><span><span style="color: #0000ff;">int</span> <br /></span><span style="mso-spacerun: yes"><span style="color: #000000;"> </span></span><span><span style="color: #808080;">,</span></span><span style="color: #000000;">[size_with_current_compression_setting (KB)] </span></span><span style="font-family: Lucida Console;"><span><span style="color: #0000ff;">bigint</span> <br /></span><span style="mso-spacerun: yes"><span style="color: #000000;"> </span></span><span><span style="color: #808080;">,</span></span><span style="color: #000000;">[size_with_requested_compression_setting (KB)] </span><span><span style="color: #0000ff;">bigint</span></span></span><span style="font-family: Lucida Console;"><span style="color: #000000;"> <br /><span style="mso-spacerun: yes"> </span></span><span><span style="color: #808080;">,</span></span><span style="color: #000000;">[sample_size_with_current_compression_setting (KB)] </span><span><span style="color: #0000ff;">bigint</span></span></span><span style="font-family: Lucida Console;"><span style="color: #000000;"> <br /><span style="mso-spacerun: yes"> </span></span><span><span style="color: #808080;">,</span></span><span style="color: #000000;">[sample_size_with_requested_compression_setting (KB)] </span></span><span><span style="font-family: Lucida Console;"><span style="color: #0000ff;">bigint</span> <br /></span></span><span><span style="font-family: Lucida Console;"><span style="color: #808080;">)</span> <br /></span></span><span><span style="font-family: Lucida Console;"><span style="color: #0000ff;">go</span> <br /> <br /></span></span><span style="font-family: Lucida Console;"><span><span style="color: #008000;">-- Calculate estimated impact of page level compression for all                      <br />-- user-tables and indexes in all schemas.                       <br />-- NOTE:                       <br />--<span style="mso-spacerun: yes"> </span>1) To get the estimated impact of row level compression change the last parameter                       <br />--<span style="mso-spacerun: yes"> </span>of sp_estimate_data_compression_savings to 'row' instead.                       <br />--<span style="mso-spacerun: yes"> </span>2) We don't care about partitioning here. If this is important for you,                       <br />--<span style="mso-spacerun: yes"> </span>you have to modify forth parameter of sp_estimate_data_compression_savings.                       <br />--<span style="mso-spacerun: yes"> </span>Please refer to BOL.</span> <br /></span><span><span style="color: #0000ff;">declare</span></span><span style="color: #000000;"> @cmd </span><span><span style="color: #0000ff;">nvarchar</span></span><span><span style="color: #808080;">(</span></span><span><span style="color: #ff00ff;">max</span></span></span><span style="font-family: Lucida Console;"><span><span style="color: #808080;">)</span> <br /></span><span><span style="color: #0000ff;">set</span></span><span style="color: #000000;"> @cmd </span><span><span style="color: #808080;">=</span></span><span style="color: #000000;"> </span></span><span style="font-family: Lucida Console;"><span><span style="color: #ff0000;">''</span> <br /></span><span><span style="color: #0000ff;">select</span></span><span style="color: #000000;"> @cmd </span><span><span style="color: #808080;">=</span></span></span><span style="font-family: Lucida Console;"><span style="color: #000000;"> @cmd                    <br /><span style="mso-spacerun: yes"> </span></span><span><span style="color: #808080;">+</span></span></span><span style="font-family: Lucida Console;"><span><span style="color: #ff0000;">';insert #comp exec sp_estimate_data_compression_savings '''</span> <br /></span><span style="mso-spacerun: yes"><span style="color: #000000;"> </span></span></span></span><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes"><span style="font-family: Lucida Console; color: #808080;">+</span></span><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes"><span style="font-family: Lucida Console;"><span style="color: #000000;"> </span><span><span style="color: #ff00ff;">schema_name</span></span><span><span style="color: #808080;">(</span></span><span><span style="color: #ff00ff;">schema_id</span></span><span><span style="color: #808080;">)+</span></span></span><span style="font-family: Lucida Console;"><span><span style="color: #ff0000;">''','''</span> <br /></span><span style="mso-spacerun: yes"><span style="color: #000000;"> </span></span></span></span><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><span style="font-family: Lucida Console; color: #808080;">+</span></span><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><span style="font-family: Lucida Console;"><span style="color: #000000;"> name </span><span><span style="color: #808080;">+</span></span><span style="color: #000000;"> </span></span><span style="font-family: Lucida Console;"><span><span style="color: #ff0000;">''',null, null, ''page'''</span> <br /></span><span style="mso-spacerun: yes"><span style="color: #000000;"> </span></span><span><span style="color: #0000ff;">from</span></span><span style="color: #000000;"> </span><span><span style="color: #008000;">sys</span></span><span><span style="color: #808080;">.</span></span></span><span style="font-family: Lucida Console;"><span><span style="color: #008000;">tables</span> <br /></span><span style="mso-spacerun: yes"><span style="color: #000000;"> </span></span><span><span style="color: #0000ff;">where</span></span><span style="color: #000000;"> </span><span><span style="color: #ff00ff;">objectproperty</span></span><span><span style="color: #808080;">(</span></span><span><span style="color: #ff00ff;">object_id</span></span><span><span style="color: #808080;">,</span></span><span style="color: #000000;"> </span><span><span style="color: #ff0000;">'IsUserTable'</span></span><span><span style="color: #808080;">)</span></span><span style="color: #000000;"> </span><span><span style="color: #808080;">=</span></span><span style="color: #000000;"> 1</span> <br /></span></span><span style="font-family: Lucida Console;"><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes"><span style="color: #0000ff;">exec </span></span><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes"><span style="color: #808080;">(</span></span></span><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes"><span style="font-family: Lucida Console; color: #000000;">@cmd</span><span><span style="font-family: Lucida Console; color: #808080;">)                    <br /> <br /></span></span></span><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><span style="font-family: Lucida Console;"><span style="color: #808080;">;</span> <br /></span></span><span style="font-family: Lucida Console;"><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><span style="color: #008000;">-- Do some further calculations for a more meaningful result</span> <br /></span><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><span style="color: #0000ff;">with</span></span></span><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><span style="font-family: Lucida Console; color: #000000;"> compressionSavings </span><span><span style="font-family: Lucida Console;"><span style="color: #0000ff;">as</span> <br /></span></span><span style="font-family: Lucida Console;"><span><span style="color: #808080;">(</span> <br /></span><span style="mso-spacerun: yes"><span style="color: #000000;"> </span></span><span><span style="color: #0000ff;">select</span></span><span style="color: #000000;"> </span><span><span style="color: #ff00ff;">quotename</span></span><span><span style="color: #808080;">(</span></span><span><span style="color: #ff00ff;">schema_name</span></span><span><span style="color: #808080;">)</span></span><span style="color: #000000;"> </span><span><span style="color: #808080;">+</span></span><span style="color: #000000;"> </span><span><span style="color: #ff0000;">'.'</span></span><span style="color: #000000;"> </span><span><span style="color: #808080;">+</span></span><span style="color: #000000;"> </span><span><span style="color: #ff00ff;">quotename</span></span><span><span style="color: #808080;">(</span></span><span><span style="color: #ff00ff;">object_name</span></span><span><span style="color: #808080;">)</span></span><span style="color: #000000;"> </span><span><span style="color: #0000ff;">as</span></span></span><span style="font-family: Lucida Console;"><span style="color: #000000;"> table_name                    <br /><span style="mso-spacerun: yes"> </span></span><span><span style="color: #808080;">,</span></span></span><span style="font-family: Lucida Console;"><span style="color: #000000;">index_id                    <br /><span style="mso-spacerun: yes"> </span></span><span><span style="color: #808080;">,</span></span></span><span style="font-family: Lucida Console;"><span style="color: #000000;">[size_with_current_compression_setting (KB)]                    <br /><span style="mso-spacerun: yes"> </span></span><span><span style="color: #808080;">,</span></span></span><span style="font-family: Lucida Console;"><span style="color: #000000;">[size_with_requested_compression_setting (KB)]                    <br /><span style="mso-spacerun: yes"> </span></span><span><span style="color: #808080;">,</span></span><span><span style="color: #ff00ff;">cast</span></span><span><span style="color: #808080;">(</span></span></span><span style="font-family: Lucida Console;"><span><span style="color: #0000ff;">case</span> <br /></span><span style="mso-spacerun: yes"><span style="color: #000000;"> </span></span><span><span style="color: #0000ff;">when</span></span><span style="color: #000000;"> [size_with_current_compression_setting (KB)] </span><span><span style="color: #808080;">=</span></span><span style="color: #000000;"> 0 </span><span><span style="color: #0000ff;">then</span></span></span><span style="font-family: Lucida Console;"><span style="color: #000000;"> 0                    <br /><span style="mso-spacerun: yes"> </span></span><span><span style="color: #0000ff;">else</span></span><span style="color: #000000;"> 100.0</span><span><span style="color: #808080;">*(</span></span><span style="color: #000000;">1.0</span><span><span style="color: #808080;">-</span></span></span><span style="font-family: Lucida Console;"><span style="color: #000000;">1.0                    <br /><span style="mso-spacerun: yes"> </span></span><span><span style="color: #808080;">*</span></span></span><span style="font-family: Lucida Console;"><span style="color: #000000;">[size_with_requested_compression_setting (KB)]                    <br /><span style="mso-spacerun: yes"> </span></span><span><span style="color: #808080;">/</span></span><span style="color: #000000;">[size_with_current_compression_setting (KB)]</span></span><span style="font-family: Lucida Console;"><span><span style="color: #808080;">)</span> <br /></span><span style="mso-spacerun: yes"><span style="color: #000000;"> </span></span><span><span style="color: #0000ff;">end</span></span><span style="color: #000000;"> </span><span><span style="color: #0000ff;">as</span></span><span style="color: #000000;"> </span><span><span style="color: #0000ff;">decimal</span></span><span><span style="color: #808080;">(</span></span><span style="color: #000000;">6</span><span><span style="color: #808080;">,</span></span><span style="color: #000000;">2</span><span><span style="color: #808080;">))</span></span><span style="color: #000000;"> </span><span><span style="color: #0000ff;">as</span></span></span><span style="font-family: Lucida Console;"><span style="color: #000000;"> [Estimated Savings (%)]                    <br /><span style="mso-spacerun: yes"> </span></span><span><span style="color: #0000ff;">from</span></span><span style="color: #000000;"> #comp</span> <br /></span><span style="font-family: Lucida Console;"><span><span style="color: #808080;">)</span> <br /></span><span><span style="color: #0000ff;">select</span></span><span style="color: #000000;"> cs</span><span><span style="color: #808080;">.</span></span></span><span style="font-family: Lucida Console;"><span style="color: #000000;">table_name                    <br /><span style="mso-spacerun: yes"> </span></span><span><span style="color: #808080;">,</span></span><span><span style="color: #ff00ff;">isnull</span></span><span><span style="color: #808080;">(</span></span><span style="color: #000000;">i</span><span><span style="color: #808080;">.</span></span><span style="color: #000000;">name</span><span><span style="color: #808080;">,</span></span><span style="color: #000000;"> i</span><span><span style="color: #808080;">.</span></span><span style="color: #000000;">type_desc</span><span><span style="color: #808080;">)</span></span><span style="color: #000000;"> </span><span><span style="color: #0000ff;">as</span></span></span><span style="font-family: Lucida Console;"><span style="color: #000000;"> index_name                    <br /><span style="mso-spacerun: yes"> </span></span><span><span style="color: #808080;">,</span></span><span style="color: #000000;">cs</span><span><span style="color: #808080;">.</span></span></span><span style="font-family: Lucida Console;"><span style="color: #000000;">[size_with_current_compression_setting (KB)]                    <br /><span style="mso-spacerun: yes"> </span></span><span><span style="color: #808080;">,</span></span><span style="color: #000000;">cs</span><span><span style="color: #808080;">.</span></span></span><span style="font-family: Lucida Console;"><span style="color: #000000;">[size_with_requested_compression_setting (KB)]                    <br /><span style="mso-spacerun: yes"> </span></span><span><span style="color: #808080;">,</span></span><span style="color: #000000;">cs</span><span><span style="color: #808080;">.</span></span><span style="color: #000000;">[Estimated Savings (%)]</span></span><span style="font-family: Lucida Console;"><span> <br /></span><span style="mso-spacerun: yes"><span style="color: #000000;"> </span></span><span><span style="color: #0000ff;">from</span></span><span style="color: #000000;"> compressionSavings </span><span><span style="color: #0000ff;">as</span></span></span><span style="font-family: Lucida Console;"><span style="color: #000000;"> cs                    <br /><span style="mso-spacerun: yes"> </span></span><span><span style="color: #808080;">left</span></span><span style="color: #000000;"> </span><span><span style="color: #808080;">outer</span></span><span style="color: #000000;"> </span><span><span style="color: #808080;">join</span></span><span style="color: #000000;"> </span><span><span style="color: #008000;">sys</span></span><span><span style="color: #808080;">.</span></span><span><span style="color: #008000;">indexes</span></span><span style="color: #000000;"> </span><span><span style="color: #0000ff;">as</span></span></span><span style="font-family: Lucida Console;"><span style="color: #000000;"> i                    <br /><span style="mso-spacerun: yes"> </span></span><span><span style="color: #0000ff;">on</span></span><span style="color: #000000;"> i</span><span><span style="color: #808080;">.</span></span><span style="color: #000000;">index_id </span><span><span style="color: #808080;">=</span></span><span style="color: #000000;"> cs</span><span><span style="color: #808080;">.</span></span></span><span style="font-family: Lucida Console;"><span style="color: #000000;">index_id                    <br /><span style="mso-spacerun: yes"> </span></span><span><span style="color: #808080;">and</span></span><span style="color: #000000;"> i</span><span><span style="color: #808080;">.</span></span><span><span style="color: #ff00ff;">object_id</span></span><span style="color: #000000;"> </span><span><span style="color: #808080;">=</span></span><span style="color: #000000;"> </span><span><span style="color: #ff00ff;">object_id</span></span><span><span style="color: #808080;">(</span></span><span style="color: #000000;">cs</span><span><span style="color: #808080;">.</span></span><span style="color: #000000;">table_name</span><span><span style="color: #808080;">,</span></span><span style="color: #000000;"> </span><span><span style="color: #ff0000;">'U'</span></span></span><span style="font-family: Lucida Console;"><span><span style="color: #808080;">)</span> <br /></span><span style="mso-spacerun: yes"><span style="color: #000000;"> </span></span><span><span style="color: #0000ff;">order</span></span><span style="color: #000000;"> </span><span><span style="color: #0000ff;">by</span></span><span style="color: #000000;"> cs</span><span><span style="color: #808080;">.</span></span><span style="color: #000000;">[Estimated Savings (%)] </span></span><span><span style="font-family: Lucida Console;"><span style="color: #0000ff;">desc</span> <br /> <br /></span></span><span><span style="font-family: Lucida Console;"><span style="color: #008000;">-- Get rid of the temp table</span> <br /></span></span></span><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes"><span style="font-family: Lucida Console; color: #0000ff;">drop</span></span></span><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes"><span style="font-family: Lucida Console;"><span style="font-size: 11pt;"><span style="color: #000000;"> </span><span><span style="color: #0000ff;">table</span></span><span style="color: #000000;"> #comp</span> <br /></span><span><span style="font-size: 11pt; color: #0000ff;">go</span></span></span></span></p>
</td>
</tr>
</tbody>
</table>
<p>The script calculates the impact of Page level compression but may easily be adapted to consider Row level compression instead. Please read the comments inside the script. Also, please notice that the script will only run on SQL Server Enterprise and Developer edition. All other editions don't provide the opportunity for data compression.</p>
<p>Here's a partial result retrieved from running the script against the <em>AdventureWorksDW2008R2</em> database.</p>
<p><a href="/blogs/media/blogs/holgerschmeling/windows-live-writer/44bf6e1fbe53_9687/image_2.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" src="/blogs/media/blogs/holgerschmeling/windows-live-writer/44bf6e1fbe53_9687/image_thumb.png" border="0" alt="image" width="955" height="186" /></a></p>
<p>If you execute the script, please be aware that it may produce some extensive I/O. Running the script against your production database at business hours wouldn't be a very good idea therefore.</p>]]></content:encoded>
								<comments>https://www.insidesql.org/blogs/holgerschmeling/2011/02/27/calculating-sql-server-data-compression-savings#comments</comments>
			<wfw:commentRss>https://www.insidesql.org/blogs/holgerschmeling/?tempskin=_rss2&#38;disp=comments&#38;p=2706</wfw:commentRss>
		</item>
				<item>
			<title>SQL Server Start Time</title>
			<link>https://www.insidesql.org/blogs/holgerschmeling/2011/02/22/sql-server-start-time</link>
			<pubDate>Tue, 22 Feb 2011 07:12:44 +0000</pubDate>			<dc:creator>Holger Schmeling</dc:creator>
			<category domain="alt">SQL Server Administration</category>
<category domain="alt">SQL Server Tips</category>
<category domain="main">Monitoring</category>			<guid isPermaLink="false">2673@https://www.insidesql.org/blogs/</guid>
						<description>&lt;p&gt;Have you tried finding out the time, your SQL Server instance has been started? There are some sophisticated solutions, like the one from Tracy Hamlin (&lt;a href=&quot;http://twitter.com/tracyhhamlin&quot;&gt;twitter&lt;/a&gt;), which takes advantage of the fact that tempdb is re-created every time, SQL Server starts. Her solution goes like this:&lt;/p&gt;
&lt;table class=&quot;MsoTableGrid&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8db3e2; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8db3e2; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102&quot; border=&quot;1&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;&gt;
&lt;tbody&gt;
&lt;tr style=&quot;mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes&quot;&gt;
&lt;td style=&quot;border-bottom: #8db3e2 1pt dashed; border-left: #8db3e2 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; border-top: #8db3e2 1pt dashed; border-right: #8db3e2 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102&quot; width=&quot;905&quot; valign=&quot;top&quot;&gt;
&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none&quot;&gt;&lt;span style=&quot;font-family: ; mso-bidi-font-family: &#039;Times New Roman&#039;; mso-ansi-language: en-us; mso-no-proof: yes&quot; lang=&quot;EN-US&quot;&gt;&lt;span style=&quot;font-family: Lucida Console; color: #0000ff;&quot;&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;select&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: ; mso-bidi-font-family: &#039;Times New Roman&#039;; mso-ansi-language: en-us; mso-no-proof: yes&quot; lang=&quot;EN-US&quot;&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; create_date                    &lt;br /&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;from&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;sys&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;databases&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;where&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; database_id&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;=&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;2&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Another answer to the question, I&#039;ve seen sometimes on the internet queries the login time for any of the system processes:&lt;/p&gt;
&lt;table class=&quot;MsoTableGrid&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8db3e2; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8db3e2; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102&quot; border=&quot;1&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;&gt;
&lt;tbody&gt;
&lt;tr style=&quot;mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes&quot;&gt;
&lt;td style=&quot;border-bottom: #8db3e2 1pt dashed; border-left: #8db3e2 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; border-top: #8db3e2 1pt dashed; border-right: #8db3e2 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102&quot; width=&quot;905&quot; valign=&quot;top&quot;&gt;
&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none&quot;&gt;&lt;span style=&quot;font-family: ; mso-bidi-font-family: &#039;Times New Roman&#039;; mso-ansi-language: en-us; mso-no-proof: yes&quot; lang=&quot;EN-US&quot;&gt;&lt;span style=&quot;font-family: Lucida Console; color: #0000ff;&quot;&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;select&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: ; mso-bidi-font-family: &#039;Times New Roman&#039;; mso-ansi-language: en-us; mso-no-proof: yes&quot; lang=&quot;EN-US&quot;&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; login_time                    &lt;br /&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;from&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;sys&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;dm_exec_sessions&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;where&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; session_id&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;=&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;This was my preferred way - until yesterday, when I discovered the following simple method:&lt;/p&gt;
&lt;table class=&quot;MsoTableGrid&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8db3e2; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8db3e2; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102&quot; border=&quot;1&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;&gt;
&lt;tbody&gt;
&lt;tr style=&quot;mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes&quot;&gt;
&lt;td style=&quot;border-bottom: #8db3e2 1pt dashed; border-left: #8db3e2 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; border-top: #8db3e2 1pt dashed; border-right: #8db3e2 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102&quot; width=&quot;905&quot; valign=&quot;top&quot;&gt;
&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none&quot;&gt;&lt;span style=&quot;font-family: ; mso-bidi-font-family: &#039;Times New Roman&#039;; mso-ansi-language: en-us; mso-no-proof: yes&quot; lang=&quot;EN-US&quot;&gt;&lt;span style=&quot;font-family: Lucida Console; color: #0000ff;&quot;&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;select&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: ; mso-bidi-font-family: &#039;Times New Roman&#039;; mso-ansi-language: en-us; mso-no-proof: yes&quot; lang=&quot;EN-US&quot;&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; sqlserver_start_time                    &lt;br /&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;from&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;sys&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;font-size: 11pt; color: #008000;&quot;&gt;dm_os_sys_info&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Easy, isn&#039;t it? Interestingly though, every of the above three queries yields a different result. Here&#039;s a query with a sample output:&lt;/p&gt;
&lt;table class=&quot;MsoTableGrid&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8db3e2; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8db3e2; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102&quot; border=&quot;1&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;&gt;
&lt;tbody&gt;
&lt;tr style=&quot;mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes&quot;&gt;
&lt;td style=&quot;border-bottom: #8db3e2 1pt dashed; border-left: #8db3e2 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; border-top: #8db3e2 1pt dashed; border-right: #8db3e2 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102&quot; width=&quot;905&quot; valign=&quot;top&quot;&gt;
&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none&quot;&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;font-family: ; mso-bidi-font-family: &#039;Times New Roman&#039;; mso-ansi-language: en-us; mso-no-proof: yes&quot; lang=&quot;EN-US&quot;&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;select &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;&lt;span style=&quot;font-family: ; mso-bidi-font-family: &#039;Times New Roman&#039;; mso-ansi-language: en-us; mso-no-proof: yes&quot; lang=&quot;EN-US&quot;&gt;&lt;span style=&quot;color: #808080;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: ; mso-bidi-font-family: &#039;Times New Roman&#039;; mso-ansi-language: en-us; mso-no-proof: yes&quot; lang=&quot;EN-US&quot;&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;select&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: ; mso-bidi-font-family: &#039;Times New Roman&#039;; mso-ansi-language: en-us; mso-no-proof: yes&quot; lang=&quot;EN-US&quot;&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; sqlserver_start_time                    &lt;br /&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;from&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;sys&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;dm_os_sys_info&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;as&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; sql_server_start_time                    &lt;br /&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;,(&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;select&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; create_date                    &lt;br /&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;from&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;sys&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;databases&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;where&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; database_id&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;=&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;2&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;as&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; tempdb_creation_time                    &lt;br /&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;,(&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;select&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;font-size: 11pt;&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; login_time                    &lt;br /&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;from&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;sys&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;dm_exec_sessions&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;where&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; session_id&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;=&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;1&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;as&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; sysprocess_login_time&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Result:&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;/blogs/media/blogs/holgerschmeling/windows-live-writer/11d5cb6a4278_6b47/image_2.png&quot;&gt;&lt;img style=&quot;background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px&quot; title=&quot;image&quot; src=&quot;/blogs/media/blogs/holgerschmeling/windows-live-writer/11d5cb6a4278_6b47/image_thumb.png&quot; border=&quot;0&quot; alt=&quot;image&quot; width=&quot;671&quot; height=&quot;49&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;It seems the SQL Server service must be started first. Only after the service is running, tempdb is created followed by a subsequent start of all sysprocesses. I can&#039;t imagine that the diverse three times make any difference in practice, e.g. if you try finding out for how many hours your SQL Server instance is running. But out there may be existing applications that have to be aware of the difference.&lt;/p&gt;</description>
			<content:encoded><![CDATA[<p>Have you tried finding out the time, your SQL Server instance has been started? There are some sophisticated solutions, like the one from Tracy Hamlin (<a href="http://twitter.com/tracyhhamlin">twitter</a>), which takes advantage of the fact that tempdb is re-created every time, SQL Server starts. Her solution goes like this:</p>
<table class="MsoTableGrid" style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8db3e2; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8db3e2; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes">
<td style="border-bottom: #8db3e2 1pt dashed; border-left: #8db3e2 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; border-top: #8db3e2 1pt dashed; border-right: #8db3e2 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" width="905" valign="top">
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none"><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><span style="font-family: Lucida Console; color: #0000ff;"><span style="font-size: 11pt;">select</span></span></span><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><span style="font-family: Lucida Console;"><span style="font-size: 11pt;"><span style="color: #000000;"> create_date                    <br /><span style="mso-spacerun: yes"> </span></span><span><span style="color: #0000ff;">from</span></span><span style="color: #000000;"> </span><span><span style="color: #008000;">sys</span></span><span><span style="color: #808080;">.</span></span><span><span style="color: #008000;">databases</span></span><span style="color: #000000;"> </span><span><span style="color: #0000ff;">where</span></span><span style="color: #000000;"> database_id</span><span><span style="color: #808080;">=</span></span><span style="color: #000000;">2</span></span></span></span></p>
</td>
</tr>
</tbody>
</table>
<p>Another answer to the question, I've seen sometimes on the internet queries the login time for any of the system processes:</p>
<table class="MsoTableGrid" style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8db3e2; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8db3e2; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes">
<td style="border-bottom: #8db3e2 1pt dashed; border-left: #8db3e2 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; border-top: #8db3e2 1pt dashed; border-right: #8db3e2 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" width="905" valign="top">
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none"><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><span style="font-family: Lucida Console; color: #0000ff;"><span style="font-size: 11pt;">select</span></span></span><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><span style="font-family: Lucida Console;"><span style="font-size: 11pt;"><span style="color: #000000;"> login_time                    <br /><span style="mso-spacerun: yes"> </span></span><span><span style="color: #0000ff;">from</span></span><span style="color: #000000;"> </span><span><span style="color: #008000;">sys</span></span><span><span style="color: #808080;">.</span></span><span><span style="color: #008000;">dm_exec_sessions</span></span><span style="color: #000000;"> </span><span><span style="color: #0000ff;">where</span></span><span style="color: #000000;"> session_id</span><span><span style="color: #808080;">=</span></span><span style="color: #000000;">1</span></span></span></span></p>
</td>
</tr>
</tbody>
</table>
<p>This was my preferred way - until yesterday, when I discovered the following simple method:</p>
<table class="MsoTableGrid" style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8db3e2; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8db3e2; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes">
<td style="border-bottom: #8db3e2 1pt dashed; border-left: #8db3e2 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; border-top: #8db3e2 1pt dashed; border-right: #8db3e2 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" width="905" valign="top">
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none"><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><span style="font-family: Lucida Console; color: #0000ff;"><span style="font-size: 11pt;">select</span></span></span><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><span style="font-family: Lucida Console;"><span style="font-size: 11pt;"><span style="color: #000000;"> sqlserver_start_time                    <br /><span style="mso-spacerun: yes"> </span></span><span><span style="color: #0000ff;">from</span></span><span style="color: #000000;"> </span><span><span style="color: #008000;">sys</span></span><span><span style="color: #808080;">.</span></span></span><span><span style="font-size: 11pt; color: #008000;">dm_os_sys_info</span></span></span></span></p>
</td>
</tr>
</tbody>
</table>
<p>Easy, isn't it? Interestingly though, every of the above three queries yields a different result. Here's a query with a sample output:</p>
<table class="MsoTableGrid" style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8db3e2; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8db3e2; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes">
<td style="border-bottom: #8db3e2 1pt dashed; border-left: #8db3e2 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; border-top: #8db3e2 1pt dashed; border-right: #8db3e2 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" width="905" valign="top">
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none"><span style="font-family: Lucida Console;"><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><span style="color: #0000ff;"><span style="font-size: 11pt;">select </span></span></span><span style="font-size: 11pt;"><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><span style="color: #808080;">(</span></span><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><span style="color: #0000ff;">select</span></span></span></span><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><span style="font-size: 11pt;"><span style="font-family: Lucida Console;"><span style="color: #000000;"> sqlserver_start_time                    <br /><span style="mso-spacerun: yes"> </span></span><span><span style="color: #0000ff;">from</span></span><span style="color: #000000;"> </span><span><span style="color: #008000;">sys</span></span><span><span style="color: #808080;">.</span></span><span><span style="color: #008000;">dm_os_sys_info</span></span><span><span style="color: #808080;">)</span></span><span style="color: #000000;"> </span><span><span style="color: #0000ff;">as</span></span></span><span style="font-family: Lucida Console;"><span style="color: #000000;"> sql_server_start_time                    <br /><span style="mso-spacerun: yes"> </span></span><span><span style="color: #808080;">,(</span></span><span><span style="color: #0000ff;">select</span></span></span><span style="font-family: Lucida Console;"><span style="color: #000000;"> create_date                    <br /><span style="mso-spacerun: yes"> </span></span><span><span style="color: #0000ff;">from</span></span><span style="color: #000000;"> </span><span><span style="color: #008000;">sys</span></span><span><span style="color: #808080;">.</span></span><span><span style="color: #008000;">databases</span></span><span style="color: #000000;"> </span><span><span style="color: #0000ff;">where</span></span><span style="color: #000000;"> database_id</span><span><span style="color: #808080;">=</span></span><span style="color: #000000;">2</span><span><span style="color: #808080;">)</span></span><span style="color: #000000;"> </span><span><span style="color: #0000ff;">as</span></span></span><span style="font-family: Lucida Console;"><span style="color: #000000;"> tempdb_creation_time                    <br /><span style="mso-spacerun: yes"> </span></span><span><span style="color: #808080;">,(</span></span><span><span style="color: #0000ff;">select</span></span></span></span><span style="font-family: Lucida Console;"><span style="font-size: 11pt;"><span style="color: #000000;"> login_time                    <br /><span style="mso-spacerun: yes"> </span></span><span><span style="color: #0000ff;">from</span></span><span style="color: #000000;"> </span><span><span style="color: #008000;">sys</span></span><span><span style="color: #808080;">.</span></span><span><span style="color: #008000;">dm_exec_sessions</span></span><span style="color: #000000;"> </span><span><span style="color: #0000ff;">where</span></span><span style="color: #000000;"> session_id</span><span><span style="color: #808080;">=</span></span><span style="color: #000000;">1</span><span><span style="color: #808080;">)</span></span><span style="color: #000000;"> </span><span><span style="color: #0000ff;">as</span></span><span style="color: #000000;"> sysprocess_login_time</span></span></span></span></p>
</td>
</tr>
</tbody>
</table>
<p>Result:</p>
<p><a href="/blogs/media/blogs/holgerschmeling/windows-live-writer/11d5cb6a4278_6b47/image_2.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" src="/blogs/media/blogs/holgerschmeling/windows-live-writer/11d5cb6a4278_6b47/image_thumb.png" border="0" alt="image" width="671" height="49" /></a></p>
<p>It seems the SQL Server service must be started first. Only after the service is running, tempdb is created followed by a subsequent start of all sysprocesses. I can't imagine that the diverse three times make any difference in practice, e.g. if you try finding out for how many hours your SQL Server instance is running. But out there may be existing applications that have to be aware of the difference.</p>]]></content:encoded>
								<comments>https://www.insidesql.org/blogs/holgerschmeling/2011/02/22/sql-server-start-time#comments</comments>
			<wfw:commentRss>https://www.insidesql.org/blogs/holgerschmeling/?tempskin=_rss2&#38;disp=comments&#38;p=2673</wfw:commentRss>
		</item>
				<item>
			<title>Exploring SQL Server Blockings and Timeouts</title>
			<link>https://www.insidesql.org/blogs/holgerschmeling/2011/01/16/exploring-sql-server-blockings-and-timeouts-1</link>
			<pubDate>Sun, 16 Jan 2011 07:31:55 +0000</pubDate>			<dc:creator>Holger Schmeling</dc:creator>
			<category domain="alt">SQL Server Performance</category>
<category domain="alt">Monitoring</category>
<category domain="main">Presentations</category>			<guid isPermaLink="false">2398@https://www.insidesql.org/blogs/</guid>
						<description>&lt;p&gt;Last Thursday I was giving a presentation about information collection and evaluation of SQL Server Blockings and Timeouts at the regional PASS chapter meeting in Munich.&lt;/p&gt;
&lt;p&gt;You may download the presentation as well as the corresponding scripts &lt;a href=&quot;http://sqlserver-presentations.com/Presentations/SQL Server Blockings and Timeouts.zip&quot;&gt;here&lt;/a&gt; (German only).&lt;/p&gt;</description>
			<content:encoded><![CDATA[<p>Last Thursday I was giving a presentation about information collection and evaluation of SQL Server Blockings and Timeouts at the regional PASS chapter meeting in Munich.</p>
<p>You may download the presentation as well as the corresponding scripts <a href="http://sqlserver-presentations.com/Presentations/SQL Server Blockings and Timeouts.zip">here</a> (German only).</p>]]></content:encoded>
								<comments>https://www.insidesql.org/blogs/holgerschmeling/2011/01/16/exploring-sql-server-blockings-and-timeouts-1#comments</comments>
			<wfw:commentRss>https://www.insidesql.org/blogs/holgerschmeling/?tempskin=_rss2&#38;disp=comments&#38;p=2398</wfw:commentRss>
		</item>
				<item>
			<title>How useful is your backup?</title>
			<link>https://www.insidesql.org/blogs/holgerschmeling/2010/12/09/how-useful-is-your-backup</link>
			<pubDate>Thu, 09 Dec 2010 18:49:00 +0000</pubDate>			<dc:creator>Holger Schmeling</dc:creator>
			<category domain="main">SQL Server Administration</category>			<guid isPermaLink="false">2091@https://www.insidesql.org/blogs/</guid>
						<description>&lt;p&gt;&lt;em&gt;A backup is worth nothing, if you can&#039;t utilize it for restore.&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;You probably agree with this well known word of wisdom, don&#039;t you?&lt;/p&gt;  &lt;p&gt;This week I had to learn another aspect - the hard way: There are many cases that may require a restore. Only one of those cases is recovering a database from a state of failure. Another situation may require access to legacy data of a meanwhile deactivated database, a database that doesn&#039;t exist anymore. In this case only a successful restore from an older backup, although necessary, may not be sufficient. Here&#039;s the story, why.&lt;/p&gt;  &lt;p&gt;I was called by a customer who requested me to pull out two documents from a legacy (SQL Server 2000) database. We found an 8 year old backup we could rely on and restore worked well. Great! But then we discovered the documents had been stored in an IMAGE column and nobody had an idea how it had been encoded at the time it was stored. We soon recognized that we need the original application to get access to the documents, only to recognize that nobody had an idea where to find the installation package. Eventually I could find an 8 year old backup which included the old VB6 code. I could have used this code to rebuild the application and also an installation package only with considerable difficulties, because:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;The application uses some ActiveX components that I may not be able to find anymore. &lt;/li&gt;    &lt;li&gt;The original application run on Windows NT, so I may have to install this OS first, including the required service pack. Even if I find the installation CDs; I doubt, I will be able to find the appropriate device drivers but maybe, I can set up a virtual machine. &lt;/li&gt;    &lt;li&gt;I had to install Visual Studio 6, including the latest service pack and I had no idea where to find the installation CDs. &lt;/li&gt;    &lt;li&gt;The application may rely on deprecated SQL Server 2000 features. So I have to have a SQL Server 2000 installation on which the existing backup has to be restored. If it gets worse, I might even have to install the appropriate service pack to make the application working. I have no idea which service pack this would be, so there&#039;s a chance I have to experiment. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;I recognized that all those steps require a big effort and will take some days to accomplish. If only we had built a virtual machine of at least one legacy client system before replacing all client PCs by newer machines.&lt;/p&gt;  &lt;p&gt;So, I&#039;d modify the introductory statement like this:&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;em&gt;A backup is worth nothing, if you can&#039;t utilize the data that is contained inside this backup.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;</description>
			<content:encoded><![CDATA[<p><em>A backup is worth nothing, if you can't utilize it for restore.</em></p>  <p>You probably agree with this well known word of wisdom, don't you?</p>  <p>This week I had to learn another aspect - the hard way: There are many cases that may require a restore. Only one of those cases is recovering a database from a state of failure. Another situation may require access to legacy data of a meanwhile deactivated database, a database that doesn't exist anymore. In this case only a successful restore from an older backup, although necessary, may not be sufficient. Here's the story, why.</p>  <p>I was called by a customer who requested me to pull out two documents from a legacy (SQL Server 2000) database. We found an 8 year old backup we could rely on and restore worked well. Great! But then we discovered the documents had been stored in an IMAGE column and nobody had an idea how it had been encoded at the time it was stored. We soon recognized that we need the original application to get access to the documents, only to recognize that nobody had an idea where to find the installation package. Eventually I could find an 8 year old backup which included the old VB6 code. I could have used this code to rebuild the application and also an installation package only with considerable difficulties, because:</p>  <ul>   <li>The application uses some ActiveX components that I may not be able to find anymore. </li>    <li>The original application run on Windows NT, so I may have to install this OS first, including the required service pack. Even if I find the installation CDs; I doubt, I will be able to find the appropriate device drivers but maybe, I can set up a virtual machine. </li>    <li>I had to install Visual Studio 6, including the latest service pack and I had no idea where to find the installation CDs. </li>    <li>The application may rely on deprecated SQL Server 2000 features. So I have to have a SQL Server 2000 installation on which the existing backup has to be restored. If it gets worse, I might even have to install the appropriate service pack to make the application working. I have no idea which service pack this would be, so there's a chance I have to experiment. </li> </ul>  <p>I recognized that all those steps require a big effort and will take some days to accomplish. If only we had built a virtual machine of at least one legacy client system before replacing all client PCs by newer machines.</p>  <p>So, I'd modify the introductory statement like this:</p>  <p><strong><em>A backup is worth nothing, if you can't utilize the data that is contained inside this backup.</em></strong></p>]]></content:encoded>
								<comments>https://www.insidesql.org/blogs/holgerschmeling/2010/12/09/how-useful-is-your-backup#comments</comments>
			<wfw:commentRss>https://www.insidesql.org/blogs/holgerschmeling/?tempskin=_rss2&#38;disp=comments&#38;p=2091</wfw:commentRss>
		</item>
				<item>
			<title>Multiple statistics sharing the same leading column</title>
			<link>https://www.insidesql.org/blogs/holgerschmeling/2010/11/04/multiple-statistics-sharing-the-same-leading-column</link>
			<pubDate>Thu, 04 Nov 2010 18:12:15 +0000</pubDate>			<dc:creator>Holger Schmeling</dc:creator>
			<category domain="main">SQL Server Administration</category>
<category domain="alt">SQL Server Performance</category>			<guid isPermaLink="false">1738@https://www.insidesql.org/blogs/</guid>
						<description>&lt;p&gt;SQL Server will not prevent you from creating identical indexes or statistics. You may think that everything is under your control, but have you ever added a missing index that has been reported by the query optimizer, or the DTA? If so, you will certainly have created duplicate statistics. Have a look at the following example:&lt;/p&gt;
&lt;table class=&quot;MsoTableGrid&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8db3e2; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8db3e2; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102&quot; border=&quot;1&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;&gt;
&lt;tbody&gt;
&lt;tr style=&quot;mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes&quot;&gt;
&lt;td style=&quot;border-bottom: #8db3e2 1pt dashed; border-left: #8db3e2 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; border-top: #8db3e2 1pt dashed; border-right: #8db3e2 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102&quot; width=&quot;905&quot; valign=&quot;top&quot;&gt;
&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none&quot;&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;font-family: ; mso-bidi-font-family: &#039;Times New Roman&#039;; mso-ansi-language: en-us; mso-no-proof: yes&quot; lang=&quot;EN-US&quot;&gt;&lt;span style=&quot;color: #008000;&quot;&gt;-- create test table with 3 columns                    &lt;br /&gt;-- filler is only nedded to widen the row&lt;/span&gt; &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-family: ; mso-bidi-font-family: &#039;Times New Roman&#039;; mso-ansi-language: en-us; mso-no-proof: yes&quot; lang=&quot;EN-US&quot;&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;create&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: ; mso-bidi-font-family: &#039;Times New Roman&#039;; mso-ansi-language: en-us; mso-no-proof: yes&quot; lang=&quot;EN-US&quot;&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;table&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; T1&lt;/span&gt; &lt;br /&gt;&lt;span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;br /&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;c1 &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;int&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;not&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;null&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;identity&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;1&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;,&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;1&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;primary&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;key&lt;/span&gt; &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;,&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;c2 &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;int&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;not&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;null&lt;/span&gt; &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;,&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;filler &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;nchar&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;200&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;not&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;null&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;default&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;#&#039;&lt;/span&gt; &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;color: #808080;&quot;&gt;)&lt;/span&gt; &lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;go&lt;/span&gt; &lt;br /&gt; &lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;-- insert 500000 rows with random                      &lt;br /&gt;-- values between 0 and 49999 for c2&lt;/span&gt; &lt;br /&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;insert&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; T1&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;c2&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;)&lt;/span&gt; &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;select&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;top&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;500000&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #ff00ff;&quot;&gt;abs&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #ff00ff;&quot;&gt;checksum&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #ff00ff;&quot;&gt;newid&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;()))&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;%&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; 50000                    &lt;br /&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;from&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;sys&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;fulltext_system_stopwords &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;as&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; a                    &lt;br /&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;,&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;sys&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;fulltext_system_stopwords &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;as&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; b&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Before invoking the following SELECT command, allow the actual execution plan being displayed (Strg-M or selecting Query/Include Actual Execution Plan from the menu).&lt;/p&gt;
&lt;table class=&quot;MsoTableGrid&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8db3e2; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8db3e2; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102&quot; border=&quot;1&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;&gt;
&lt;tbody&gt;
&lt;tr style=&quot;mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes&quot;&gt;
&lt;td style=&quot;border-bottom: #8db3e2 1pt dashed; border-left: #8db3e2 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; border-top: #8db3e2 1pt dashed; border-right: #8db3e2 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102&quot; width=&quot;905&quot; valign=&quot;top&quot;&gt;
&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none&quot;&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;font-family: ; mso-bidi-font-family: &#039;Times New Roman&#039;; mso-ansi-language: en-us; mso-no-proof: yes&quot; lang=&quot;EN-US&quot;&gt;&lt;span style=&quot;color: #008000;&quot;&gt;-- get some data&lt;/span&gt; &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-family: ; mso-bidi-font-family: &#039;Times New Roman&#039;; mso-ansi-language: en-us; mso-no-proof: yes&quot; lang=&quot;EN-US&quot;&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;select&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: ; mso-bidi-font-family: &#039;Times New Roman&#039;; mso-ansi-language: en-us; mso-no-proof: yes&quot; lang=&quot;EN-US&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;*&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;from&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;T1&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;where&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;c2&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;=&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; 100&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;If you look at the execution plan, you see that the optimizer complains about a missing index on column c2. The prognosticated improvement is about 99%, so adding the index it&#039;s certainly a good idea. Let&#039;s do it:&lt;/p&gt;
&lt;table class=&quot;MsoTableGrid&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8db3e2; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8db3e2; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102&quot; border=&quot;1&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;&gt;
&lt;tbody&gt;
&lt;tr style=&quot;mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes&quot;&gt;
&lt;td style=&quot;border-bottom: #8db3e2 1pt dashed; border-left: #8db3e2 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; border-top: #8db3e2 1pt dashed; border-right: #8db3e2 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102&quot; width=&quot;905&quot; valign=&quot;top&quot;&gt;
&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin: 0in 0in 0pt&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;font-family: ; mso-bidi-font-family: &#039;Times New Roman&#039;; mso-ansi-language: en-us; mso-no-proof: yes&quot; lang=&quot;EN-US&quot;&gt;&lt;span style=&quot;color: #008000;&quot;&gt;-- add missing index&lt;/span&gt; &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-family: ; mso-bidi-font-family: &#039;Times New Roman&#039;; mso-ansi-language: en-us; mso-no-proof: yes&quot; lang=&quot;EN-US&quot;&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;create&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: ; mso-bidi-font-family: &#039;Times New Roman&#039;; mso-ansi-language: en-us; mso-no-proof: yes&quot; lang=&quot;EN-US&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;nonclustered&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;index&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;ix_1&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;on&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;t1&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;c2&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Perfect! The query runs much faster now and needs a lot fewer resources. But have a look at the table&#039;s statistics:&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;/blogs/media/blogs/holgerschmeling/windows-live-writer/611e11afab6f_113f3/image_2.png&quot;&gt;&lt;img style=&quot;background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px&quot; title=&quot;image&quot; src=&quot;/blogs/media/blogs/holgerschmeling/windows-live-writer/611e11afab6f_113f3/image_thumb.png&quot; border=&quot;0&quot; alt=&quot;image&quot; width=&quot;261&quot; height=&quot;220&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;You see three statistics, one for the primary key, a second one for our created index ix_1, and a third one that was automatically created during execution plan generation for the first SELECT statement. This is the statistics, named &lt;em&gt;_WA_Sys.&lt;/em&gt;. If the AUTO CREATE STATISTICS option is set to ON, the optimizer will add missing statistics automatically. In our little experiment, the optimizer had to generate this column statistics on column c2 in order to make some assumptions about the number of rows that had to be processed.&lt;/p&gt;
&lt;p&gt;And here&#039;s the problem: When creating the index on column c2, a statistics on this column is also created, since every index has a corresponding linked statistics. That&#039;s just the way it works. At the time the index was added, the column statistics on c2 (that &lt;em&gt;_WA_Sys.&lt;/em&gt; statistics) already existed. If you don&#039;t remove it manually, this statistics will remain there forever, although it is needless now. All it&#039;s good for is to increase maintenance efforts during statistics updates. You can safely remove this statistics by executing:&lt;/p&gt;
&lt;table class=&quot;MsoTableGrid&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8db3e2; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8db3e2; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102&quot; border=&quot;1&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;&gt;
&lt;tbody&gt;
&lt;tr style=&quot;mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes&quot;&gt;
&lt;td style=&quot;border-bottom: #8db3e2 1pt dashed; border-left: #8db3e2 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; border-top: #8db3e2 1pt dashed; border-right: #8db3e2 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102&quot; width=&quot;905&quot; valign=&quot;top&quot;&gt;
&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin: 0in 0in 0pt&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;font-family: ; mso-bidi-font-family: &#039;Times New Roman&#039;; mso-ansi-language: en-us; mso-no-proof: yes&quot; lang=&quot;EN-US&quot;&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;drop&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: ; mso-bidi-font-family: &#039;Times New Roman&#039;; mso-ansi-language: en-us; mso-no-proof: yes&quot; lang=&quot;EN-US&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;statistics&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;t1&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;_WA_Sys_...&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;If you didn&#039;t think about this before, there&#039;s a chance that you&#039;ll find some of those superfluous statistics duplicates inside your database(s). Here&#039;s a query that finds index-related and column-statistics that match on the first column. Looking for matches on the first column is sufficient here, since the optimizer only automatically adds missing &lt;em&gt;single-column&lt;/em&gt; statistics.&lt;/p&gt;
&lt;table class=&quot;MsoTableGrid&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8db3e2; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8db3e2; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102&quot; border=&quot;1&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;&gt;
&lt;tbody&gt;
&lt;tr style=&quot;mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes&quot;&gt;
&lt;td style=&quot;border-bottom: #8db3e2 1pt dashed; border-left: #8db3e2 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; border-top: #8db3e2 1pt dashed; border-right: #8db3e2 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102&quot; width=&quot;905&quot; valign=&quot;top&quot;&gt;
&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin: 0in 0in 0pt&quot;&gt;&lt;span style=&quot;font-family: ; mso-bidi-font-family: &#039;Times New Roman&#039;; mso-ansi-language: en-us; mso-no-proof: yes&quot; lang=&quot;EN-US&quot;&gt;&lt;span style=&quot;font-family: Lucida Console; color: #0000ff; font-size: x-small;&quot;&gt;with&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: ; mso-bidi-font-family: &#039;Times New Roman&#039;; mso-ansi-language: en-us; mso-no-proof: yes&quot; lang=&quot;EN-US&quot;&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;all_stats&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;as                      &lt;br /&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;(&lt;/span&gt; &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;select&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;s&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #ff00ff;&quot;&gt;object_id&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;,&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;s&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;name&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;as&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;stats_name&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;,&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;s&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;stats_id&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;,&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;s&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;has_filter&lt;/span&gt; &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;,&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;s&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;auto_created&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;,&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;sc&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;stats_column_id&lt;/span&gt; &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;,&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;sc&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;column_id&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;,&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;c&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;name&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;as&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;column_name&lt;/span&gt; &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;from&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #3e4118;&quot;&gt;sys&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #3e4118;&quot;&gt;stats&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;as&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;s&lt;/span&gt; &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;inner&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;join&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #3e4118;&quot;&gt;sys&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #3e4118;&quot;&gt;stats_columns&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;as&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;sc&lt;/span&gt; &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;on&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;s&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;stats_id&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;=&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;sc&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;stats_id&lt;/span&gt; &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;and&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;s&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #ff00ff;&quot;&gt;object_id&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;=&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;sc&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span&gt;&lt;span style=&quot;color: #ff00ff;&quot;&gt;object_id&lt;/span&gt; &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;and&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;sc&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;stats_column_id&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;=&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; 1                    &lt;br /&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;inner&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;join&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #3e4118;&quot;&gt;sys&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #3e4118;&quot;&gt;columns&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;as&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;c&lt;/span&gt; &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;on&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;c&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #ff00ff;&quot;&gt;object_id&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;=&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;s&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span&gt;&lt;span style=&quot;color: #ff00ff;&quot;&gt;object_id&lt;/span&gt; &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;and&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;c&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #ff00ff;&quot;&gt;object_id&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;=&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;sc&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span&gt;&lt;span style=&quot;color: #ff00ff;&quot;&gt;object_id&lt;/span&gt; &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;and&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;c&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;column_id&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;=&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;sc&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;column_id&lt;/span&gt; &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;where&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #ff00ff;&quot;&gt;objectproperty&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;s&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #ff00ff;&quot;&gt;object_id&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;,&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;IsUserTable&#039;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;=&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; 1&lt;/span&gt; &lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;)&lt;/span&gt; &lt;br /&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;select&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #ff00ff;&quot;&gt;row_number&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;()&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;over&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;partition&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;by&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;s1&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #ff00ff;&quot;&gt;object_id&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;,&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;s1&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;column_name&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;order&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;by&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;s1&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;column_name&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;as&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;stats_no&lt;/span&gt; &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;,&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #ff00ff;&quot;&gt;object_name&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;s1&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #ff00ff;&quot;&gt;object_id&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;as&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;table_name&lt;/span&gt; &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;,&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;s1&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;stats_name&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;as&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;stats_name&lt;/span&gt; &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;,&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;s2&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;stats_name&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;as&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;identical_stats_name&lt;/span&gt; &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;,&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;s2&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;column_name&lt;/span&gt; &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;from&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;all_stats&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;as&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;s1&lt;/span&gt; &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;inner&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;join&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;all_stats&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;as&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;s2&lt;/span&gt; &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;on&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;s1&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #ff00ff;&quot;&gt;object_id&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;=&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;s2&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span&gt;&lt;span style=&quot;color: #ff00ff;&quot;&gt;object_id&lt;/span&gt; &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;and&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;s1&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;stats_id&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;!=&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;s2&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;stats_id&lt;/span&gt; &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;and&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;s1&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;stats_column_id&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;=&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;s2&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;stats_column_id&lt;/span&gt; &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;and&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;s1&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;column_id&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;=&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;s2&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;column_id&lt;/span&gt; &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;and&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;s1&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;has_filter&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;=&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;s2&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Lucida Console;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;has_filter&lt;/span&gt; &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;and&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;s1&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;auto_created&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;!=&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt; &lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;s2&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;color: #008080;&quot;&gt;auto_created&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;With that query at hand, you may easily find redundant statistics. Here&#039;s a sample output:&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;/blogs/media/blogs/holgerschmeling/windows-live-writer/611e11afab6f_113f3/image_4.png&quot;&gt;&lt;img style=&quot;background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px&quot; title=&quot;image&quot; src=&quot;/blogs/media/blogs/holgerschmeling/windows-live-writer/611e11afab6f_113f3/image_thumb_1.png&quot; border=&quot;0&quot; alt=&quot;image&quot; width=&quot;790&quot; height=&quot;66&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;If you&#039;d like to find out more about SQL Server statistics, you may want to check out my series of two articles, published recently on the &lt;a href=&quot;http://www.simple-talk.com&quot;&gt;Simple-Talk&lt;/a&gt; platform.&lt;/p&gt;
&lt;p&gt;Part 1: &lt;a href=&quot;http://www.simple-talk.com/sql/performance/queries,-damned-queries-and-statistics/&quot;&gt;Queries, Damned Queries and Statistics&lt;/a&gt; &lt;br /&gt;Part 2: &lt;a href=&quot;http://www.simple-talk.com/sql/performance/sql-server-statistics-problems-and-solutions/&quot;&gt;SQL Server Statistics: Problems and Solutions&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;It&#039;s free, so you might want to give it a try. Feel free to vote, if you like it!&lt;/p&gt;</description>
			<content:encoded><![CDATA[<p>SQL Server will not prevent you from creating identical indexes or statistics. You may think that everything is under your control, but have you ever added a missing index that has been reported by the query optimizer, or the DTA? If so, you will certainly have created duplicate statistics. Have a look at the following example:</p>
<table class="MsoTableGrid" style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8db3e2; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8db3e2; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes">
<td style="border-bottom: #8db3e2 1pt dashed; border-left: #8db3e2 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; border-top: #8db3e2 1pt dashed; border-right: #8db3e2 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" width="905" valign="top">
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none"><span style="font-family: Lucida Console;"><span style="font-size: x-small;"><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><span style="color: #008000;">-- create test table with 3 columns                    <br />-- filler is only nedded to widen the row</span> <br /></span><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><span style="color: #0000ff;">create</span></span></span></span><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><span style="font-family: Lucida Console;"><span style="font-size: x-small;"><span style="color: #000000;"> </span><span><span style="color: #0000ff;">table</span></span><span style="color: #000000;"> T1</span> <br /><span><span style="mso-spacerun: yes"><span style="color: #0000ff;"> </span></span></span><span><span style="color: #808080;">(</span></span></span></span><span style="font-family: Lucida Console;"><span style="font-size: x-small;"><span style="color: #000000;"> <br /><span style="mso-spacerun: yes"> </span>c1 </span><span><span style="color: #0000ff;">int</span></span><span style="color: #000000;"> </span><span><span style="color: #808080;">not</span></span><span style="color: #000000;"> </span><span><span style="color: #808080;">null</span></span><span style="color: #000000;"> </span><span><span style="color: #0000ff;">identity</span></span><span><span style="color: #808080;">(</span></span><span style="color: #000000;">1</span><span><span style="color: #808080;">,</span></span><span style="color: #000000;">1</span><span><span style="color: #808080;">)</span></span><span style="color: #000000;"> </span><span><span style="color: #0000ff;">primary</span></span><span style="color: #000000;"> </span></span></span><span style="font-family: Lucida Console;"><span style="font-size: x-small;"><span><span style="color: #0000ff;">key</span> <br /></span><span style="mso-spacerun: yes"><span style="color: #000000;"> </span></span><span><span style="color: #808080;">,</span></span><span style="color: #000000;">c2 </span><span><span style="color: #0000ff;">int</span></span><span style="color: #000000;"> </span><span><span style="color: #808080;">not</span></span><span style="color: #000000;"> </span></span></span><span style="font-family: Lucida Console;"><span style="font-size: x-small;"><span><span style="color: #808080;">null</span> <br /></span><span style="mso-spacerun: yes"><span style="color: #000000;"> </span></span><span><span style="color: #808080;">,</span></span><span style="color: #000000;">filler </span><span><span style="color: #0000ff;">nchar</span></span><span><span style="color: #808080;">(</span></span><span style="color: #000000;">200</span><span><span style="color: #808080;">)</span></span><span style="color: #000000;"> </span><span><span style="color: #808080;">not</span></span><span style="color: #000000;"> </span><span><span style="color: #808080;">null</span></span><span style="color: #000000;"> </span><span><span style="color: #0000ff;">default</span></span><span style="color: #000000;"> </span></span></span><span style="font-family: Lucida Console;"><span style="font-size: x-small;"><span><span style="color: #ff0000;">'#'</span> <br /></span><span style="mso-spacerun: yes"><span style="color: #000000;"> </span></span></span></span><span><span style="font-family: Lucida Console;"><span style="font-size: x-small;"><span style="color: #808080;">)</span> <br /></span></span></span><span><span style="font-family: Lucida Console;"><span style="font-size: x-small;"><span style="color: #0000ff;">go</span> <br /> <br /></span></span></span><span style="font-family: Lucida Console;"><span style="font-size: x-small;"><span><span style="color: #008000;">-- insert 500000 rows with random                      <br />-- values between 0 and 49999 for c2</span> <br /></span><span><span style="color: #0000ff;">insert</span></span><span style="color: #000000;"> T1</span><span><span style="color: #808080;">(</span></span><span style="color: #000000;">c2</span></span></span><span style="font-family: Lucida Console;"><span style="font-size: x-small;"><span><span style="color: #808080;">)</span> <br /></span><span style="mso-spacerun: yes"><span style="color: #000000;"> </span></span><span><span style="color: #0000ff;">select</span></span><span style="color: #000000;"> </span><span><span style="color: #0000ff;">top</span></span><span><span style="color: #808080;">(</span></span><span style="color: #000000;">500000</span><span><span style="color: #808080;">)</span></span><span style="color: #000000;"> </span><span><span style="color: #ff00ff;">abs</span></span><span><span style="color: #808080;">(</span></span><span><span style="color: #ff00ff;">checksum</span></span><span><span style="color: #808080;">(</span></span><span><span style="color: #ff00ff;">newid</span></span><span><span style="color: #808080;">()))</span></span><span style="color: #000000;"> </span><span><span style="color: #808080;">%</span></span></span></span><span style="font-family: Lucida Console;"><span style="font-size: x-small;"><span style="color: #000000;"> 50000                    <br /><span style="mso-spacerun: yes"> </span></span><span><span style="color: #0000ff;">from</span></span><span style="color: #000000;"> </span><span><span style="color: #008000;">sys</span></span><span><span style="color: #808080;">.</span></span><span style="color: #000000;">fulltext_system_stopwords </span><span><span style="color: #0000ff;">as</span></span></span></span><span style="font-family: Lucida Console;"><span style="font-size: x-small;"><span style="color: #000000;"> a                    <br /><span style="mso-spacerun: yes"> </span></span><span><span style="color: #808080;">,</span></span><span><span style="color: #008000;">sys</span></span><span><span style="color: #808080;">.</span></span><span style="color: #000000;">fulltext_system_stopwords </span><span><span style="color: #0000ff;">as</span></span><span style="color: #000000;"> b</span></span></span></span></p>
</td>
</tr>
</tbody>
</table>
<p>Before invoking the following SELECT command, allow the actual execution plan being displayed (Strg-M or selecting Query/Include Actual Execution Plan from the menu).</p>
<table class="MsoTableGrid" style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8db3e2; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8db3e2; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes">
<td style="border-bottom: #8db3e2 1pt dashed; border-left: #8db3e2 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; border-top: #8db3e2 1pt dashed; border-right: #8db3e2 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" width="905" valign="top">
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none"><span style="font-family: Lucida Console;"><span style="font-size: x-small;"><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><span style="color: #008000;">-- get some data</span> <br /></span><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><span style="color: #0000ff;">select</span></span><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><span style="color: #000000;"> </span><span><span style="color: #808080;">*</span></span><span style="color: #000000;"> </span><span><span style="color: #0000ff;">from</span></span><span style="color: #000000;"> </span><span><span style="color: #008080;">T1</span></span><span style="color: #000000;"> </span><span><span style="color: #0000ff;">where</span></span><span style="color: #000000;"> </span><span><span style="color: #008080;">c2</span></span><span style="color: #000000;"> </span><span><span style="color: #808080;">=</span></span><span style="color: #000000;"> 100</span></span></span></span></p>
</td>
</tr>
</tbody>
</table>
<p>If you look at the execution plan, you see that the optimizer complains about a missing index on column c2. The prognosticated improvement is about 99%, so adding the index it's certainly a good idea. Let's do it:</p>
<table class="MsoTableGrid" style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8db3e2; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8db3e2; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes">
<td style="border-bottom: #8db3e2 1pt dashed; border-left: #8db3e2 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; border-top: #8db3e2 1pt dashed; border-right: #8db3e2 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" width="905" valign="top">
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt"><span style="font-size: x-small;"><span style="font-family: Lucida Console;"><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><span style="color: #008000;">-- add missing index</span> <br /></span><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><span style="color: #0000ff;">create</span></span><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><span style="color: #000000;"> </span><span><span style="color: #0000ff;">nonclustered</span></span><span style="color: #000000;"> </span><span><span style="color: #0000ff;">index</span></span><span style="color: #000000;"> </span><span><span style="color: #008080;">ix_1</span></span><span style="color: #000000;"> </span><span><span style="color: #0000ff;">on</span></span><span style="color: #000000;"> </span><span><span style="color: #008080;">t1</span></span><span><span style="color: #808080;">(</span></span><span><span style="color: #008080;">c2</span></span><span><span style="color: #808080;">)</span></span></span></span></span></p>
</td>
</tr>
</tbody>
</table>
<p>Perfect! The query runs much faster now and needs a lot fewer resources. But have a look at the table's statistics:</p>
<p><a href="/blogs/media/blogs/holgerschmeling/windows-live-writer/611e11afab6f_113f3/image_2.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" src="/blogs/media/blogs/holgerschmeling/windows-live-writer/611e11afab6f_113f3/image_thumb.png" border="0" alt="image" width="261" height="220" /></a></p>
<p>You see three statistics, one for the primary key, a second one for our created index ix_1, and a third one that was automatically created during execution plan generation for the first SELECT statement. This is the statistics, named <em>_WA_Sys.</em>. If the AUTO CREATE STATISTICS option is set to ON, the optimizer will add missing statistics automatically. In our little experiment, the optimizer had to generate this column statistics on column c2 in order to make some assumptions about the number of rows that had to be processed.</p>
<p>And here's the problem: When creating the index on column c2, a statistics on this column is also created, since every index has a corresponding linked statistics. That's just the way it works. At the time the index was added, the column statistics on c2 (that <em>_WA_Sys.</em> statistics) already existed. If you don't remove it manually, this statistics will remain there forever, although it is needless now. All it's good for is to increase maintenance efforts during statistics updates. You can safely remove this statistics by executing:</p>
<table class="MsoTableGrid" style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8db3e2; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8db3e2; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes">
<td style="border-bottom: #8db3e2 1pt dashed; border-left: #8db3e2 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; border-top: #8db3e2 1pt dashed; border-right: #8db3e2 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" width="905" valign="top">
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt"><span style="font-size: x-small;"><span style="font-family: Lucida Console;"><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><span style="color: #0000ff;">drop</span></span><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><span style="color: #000000;"> </span><span><span style="color: #0000ff;">statistics</span></span><span style="color: #000000;"> </span><span><span style="color: #008080;">t1</span></span><span><span style="color: #808080;">.</span></span><span><span style="color: #008080;">_WA_Sys_...</span></span></span></span></span></p>
</td>
</tr>
</tbody>
</table>
<p>If you didn't think about this before, there's a chance that you'll find some of those superfluous statistics duplicates inside your database(s). Here's a query that finds index-related and column-statistics that match on the first column. Looking for matches on the first column is sufficient here, since the optimizer only automatically adds missing <em>single-column</em> statistics.</p>
<table class="MsoTableGrid" style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8db3e2; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8db3e2; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes">
<td style="border-bottom: #8db3e2 1pt dashed; border-left: #8db3e2 1pt dashed; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; border-top: #8db3e2 1pt dashed; border-right: #8db3e2 1pt dashed; padding-top: 0in; mso-border-alt: dashed #8db3e2 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102" width="905" valign="top">
<p class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt"><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><span style="font-family: Lucida Console; color: #0000ff; font-size: x-small;">with</span></span><span style="font-family: ; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: en-us; mso-no-proof: yes" lang="EN-US"><span style="font-family: Lucida Console;"><span style="font-size: x-small;"><span style="color: #000000;"> </span><span><span style="color: #008080;">all_stats</span></span><span style="color: #000000;"> </span></span></span><span><span style="color: #0000ff;"><span style="font-family: Lucida Console;"><span style="font-size: x-small;">as                      <br /><span style="mso-spacerun: yes"> </span></span></span></span></span><span style="font-family: Lucida Console;"><span style="font-size: x-small;"><span><span style="color: #808080;">(</span> <br /></span><span style="mso-spacerun: yes"><span style="color: #000000;"> </span></span><span><span style="color: #0000ff;">select</span></span><span style="color: #000000;"> </span><span><span style="color: #008080;">s</span></span><span><span style="color: #808080;">.</span></span><span><span style="color: #ff00ff;">object_id</span></span><span><span style="color: #808080;">,</span></span><span style="color: #000000;"> </span><span><span style="color: #008080;">s</span></span><span><span style="color: #808080;">.</span></span><span><span style="color: #008080;">name</span></span><span style="color: #000000;"> </span><span><span style="color: #0000ff;">as</span></span><span style="color: #000000;"> </span><span><span style="color: #008080;">stats_name</span></span><span><span style="color: #808080;">,</span></span><span style="color: #000000;"> </span><span><span style="color: #008080;">s</span></span><span><span style="color: #808080;">.</span></span><span><span style="color: #008080;">stats_id</span></span><span><span style="color: #808080;">,</span></span><span style="color: #000000;"> </span><span><span style="color: #008080;">s</span></span><span><span style="color: #808080;">.</span></span></span></span><span style="font-family: Lucida Console;"><span style="font-size: x-small;"><span><span style="color: #008080;">has_filter</span> <br /></span><span style="mso-spacerun: yes"><span style="color: #000000;"> </span></span><span><span style="color: #808080;">,</span></span><span><span style="color: #008080;">s</span></span><span><span style="color: #808080;">.</span></span><span><span style="color: #008080;">auto_created</span></span><span><span style="color: #808080;">,</span></span><span style="color: #000000;"> </span><span><span style="color: #008080;">sc</span></span><span><span style="color: #808080;">.</span></span></span></span><span style="font-family: Lucida Console;"><span style="font-size: x-small;"><span><span style="color: #008080;">stats_column_id</span> <br /></span><span style="mso-spacerun: yes"><span style="color: #000000;"> </span></span><span><span style="color: #808080;">,</span></span><span><span style="color: #008080;">sc</span></span><span><span style="color: #808080;">.</span></span><span><span style="color: #008080;">column_id</span></span><span><span style="color: #808080;">,</span></span><span style="color: #000000;"> </span><span><span style="color: #008080;">c</span></span><span><span style="color: #808080;">.</span></span><span><span style="color: #008080;">name</span></span><span style="color: #000000;"> </span><span><span style="color: #0000ff;">as</span></span><span style="color: #000000;"> </span></span></span><span style="font-family: Lucida Console;"><span style="font-size: x-small;"><span><span style="color: #008080;">column_name</span> <br /></span><span style="mso-spacerun: yes"><span style="color: #000000;"> </span></span><span><span style="color: #0000ff;">from</span></span><span style="color: #000000;"> </span><span><span style="color: #3e4118;">sys</span></span><span><span style="color: #808080;">.</span></span><span><span style="color: #3e4118;">stats</span></span><span style="color: #000000;"> </span><span><span style="color: #0000ff;">as</span></span><span style="color: #000000;"> </span></span></span><span style="font-family: Lucida Console;"><span style="font-size: x-small;"><span><span style="color: #008080;">s</span> <br /></span><span style="mso-spacerun: yes"><span style="color: #000000;"> </span></span><span><span style="color: #808080;">inner</span></span><span style="color: #000000;"> </span><span><span style="color: #808080;">join</span></span><span style="color: #000000;"> </span><span><span style="color: #3e4118;">sys</span></span><span><span style="color: #808080;">.</span></span><span><span style="color: #3e4118;">stats_columns</span></span><span style="color: #000000;"> </span><span><span style="color: #0000ff;">as</span></span><span style="color: #000000;"> </span></span></span><span style="font-family: Lucida Console;"><span style="font-size: x-small;"><span><span style="color: #008080;">sc</span> <br /></span><span style="mso-spacerun: yes"><span style="color: #000000;"> </span></span><span><span style="color: #0000ff;">on</span></span><span style="color: #000000;"> </span><span><span style="color: #008080;">s</span></span><span><span style="color: #808080;">.</span></span><span><span style="color: #008080;">stats_id</span></span><span style="color: #000000;"> </span><span><span style="color: #808080;">=</span></span><span style="color: #000000;"> </span><span><span style="color: #008080;">sc</span></span><span><span style="color: #808080;">.</span></span></span></span><span style="font-family: Lucida Console;"><span style="font-size: x-small;"><span><span style="color: #008080;">stats_id</span> <br /></span><span style="mso-spacerun: yes"><span style="color: #000000;"> </span></span><span><span style="color: #808080;">and</span></span><span style="color: #000000;"> </span><span><span style="color: #008080;">s</span></span><span><span style="color: #808080;">.</span></span><span><span style="color: #ff00ff;">object_id</span></span><span style="color: #000000;"> </span><span><span style="color: #808080;">=</span></span><span style="color: #000000;"> </span><span><span style="color: #008080;">sc</span></span><span><span style="color: #808080;">.</span></span></span></span><span style="font-family: Lucida Console;"><span style="font-size: x-small;"><span><span style="color: #ff00ff;">object_id</span> <br /></span><span style="mso-spacerun: yes"><span style="color: #000000;"> </span></span><span><span style="color: #808080;">and</span></span><span style="color: #000000;"> </span><span><span style="color: #008080;">sc</span></span><span><span style="color: #808080;">.</span></span><span><span style="color: #008080;">stats_column_id</span></span><span style="color: #000000;"> </span><span><span style="color: #808080;">=</span></span></span></span><span style="font-family: Lucida Console;"><span style="font-size: x-small;"><span style="color: #000000;"> 1                    <br /><span style="mso-spacerun: yes"> </span></span><span><span style="color: #808080;">inner</span></span><span style="color: #000000;"> </span><span><span style="color: #808080;">join</span></span><span style="color: #000000;"> </span><span><span style="color: #3e4118;">sys</span></span><span><span style="color: #808080;">.</span></span><span><span style="color: #3e4118;">columns</span></span><span style="color: #000000;"> </span><span><span style="color: #0000ff;">as</span></span><span style="color: #000000;"> </span></span></span><span style="font-family: Lucida Console;"><span style="font-size: x-small;"><span><span style="color: #008080;">c</span> <br /></span><span style="mso-spacerun: yes"><span style="color: #000000;"> </span></span><span><span style="color: #0000ff;">on</span></span><span style="color: #000000;"> </span><span><span style="color: #008080;">c</span></span><span><span style="color: #808080;">.</span></span><span><span style="color: #ff00ff;">object_id</span></span><span style="color: #000000;"> </span><span><span style="color: #808080;">=</span></span><span style="color: #000000;"> </span><span><span style="color: #008080;">s</span></span><span><span style="color: #808080;">.</span></span></span></span><span style="font-family: Lucida Console;"><span style="font-size: x-small;"><span><span style="color: #ff00ff;">object_id</span> <br /></span><span style="mso-spacerun: yes"><span style="color: #000000;"> </span></span><span><span style="color: #808080;">and</span></span><span style="color: #000000;"> </span><span><span style="color: #008080;">c</span></span><span><span style="color: #808080;">.</span></span><span><span style="color: #ff00ff;">object_id</span></span><span style="color: #000000;"> </span><span><span style="color: #808080;">=</span></span><span style="color: #000000;"> </span><span><span style="color: #008080;">sc</span></span><span><span style="color: #808080;">.</span></span></span></span><span style="font-family: Lucida Console;"><span style="font-size: x-small;"><span><span style="color: #ff00ff;">object_id</span> <br /></span><span style="mso-spacerun: yes"><span style="color: #000000;"> </span></span><span><span style="color: #808080;">and</span></span><span style="color: #000000;"> </span><span><span style="color: #008080;">c</span></span><span><span style="color: #808080;">.</span></span><span><span style="color: #008080;">column_id</span></span><span style="color: #000000;"> </span><span><span style="color: #808080;">=</span></span><span style="color: #000000;"> </span><span><span style="color: #008080;">sc</span></span><span><span style="color: #808080;">.</span></span></span></span><span style="font-family: Lucida Console;"><span style="font-size: x-small;"><span><span style="color: #008080;">column_id</span> <br /></span><span style="mso-spacerun: yes"><span style="color: #000000;"> </span></span><span><span style="color: #0000ff;">where</span></span><span style="color: #000000;"> </span><span><span style="color: #ff00ff;">objectproperty</span></span><span><span style="color: #808080;">(</span></span><span><span style="color: #008080;">s</span></span><span><span style="color: #808080;">.</span></span><span><span style="color: #ff00ff;">object_id</span></span><span><span style="color: #808080;">,</span></span><span style="color: #000000;"> </span><span><span style="color: #ff0000;">'IsUserTable'</span></span><span><span style="color: #808080;">)</span></span><span style="color: #000000;"> </span><span><span style="color: #808080;">=</span></span><span style="color: #000000;"> 1</span> <br /></span></span><span style="font-family: Lucida Console;"><span style="font-size: x-small;"><span><span style="color: #808080;">)</span> <br /></span><span><span style="color: #0000ff;">select</span></span><span style="color: #000000;"> </span><span><span style="color: #ff00ff;">row_number</span></span><span><span style="color: #808080;">()</span></span><span style="color: #000000;"> </span><span><span style="color: #0000ff;">over</span></span><span><span style="color: #808080;">(</span></span><span><span style="color: #0000ff;">partition</span></span><span style="color: #000000;"> </span><span><span style="color: #0000ff;">by</span></span><span style="color: #000000;"> </span><span><span style="color: #008080;">s1</span></span><span><span style="color: #808080;">.</span></span><span><span style="color: #ff00ff;">object_id</span></span><span><span style="color: #808080;">,</span></span><span style="color: #000000;"> </span><span><span style="color: #008080;">s1</span></span><span><span style="color: #808080;">.</span></span><span><span style="color: #008080;">column_name</span></span><span style="color: #000000;"> </span><span><span style="color: #0000ff;">order</span></span><span style="color: #000000;"> </span><span><span style="color: #0000ff;">by</span></span><span style="color: #000000;"> </span><span><span style="color: #008080;">s1</span></span><span><span style="color: #808080;">.</span></span><span><span style="color: #008080;">column_name</span></span><span><span style="color: #808080;">)</span></span><span style="color: #000000;"> </span><span><span style="color: #0000ff;">as</span></span><span style="color: #000000;"> </span></span></span><span style="font-family: Lucida Console;"><span style="font-size: x-small;"><span><span style="color: #008080;">stats_no</span> <br /></span><span style="mso-spacerun: yes"><span style="color: #000000;"> </span></span><span><span style="color: #808080;">,</span></span><span><span style="color: #ff00ff;">object_name</span></span><span><span style="color: #808080;">(</span></span><span><span style="color: #008080;">s1</span></span><span><span style="color: #808080;">.</span></span><span><span style="color: #ff00ff;">object_id</span></span><span><span style="color: #808080;">)</span></span><span style="color: #000000;"> </span><span><span style="color: #0000ff;">as</span></span><span style="color: #000000;"> </span></span></span><span style="font-family: Lucida Console;"><span style="font-size: x-small;"><span><span style="color: #008080;">table_name</span> <br /></span><span style="mso-spacerun: yes"><span style="color: #000000;"> </span></span><span><span style="color: #808080;">,</span></span><span><span style="color: #008080;">s1</span></span><span><span style="color: #808080;">.</span></span><span><span style="color: #008080;">stats_name</span></span><span style="color: #000000;"> </span><span><span style="color: #0000ff;">as</span></span><span style="color: #000000;"> </span></span></span><span style="font-family: Lucida Console;"><span style="font-size: x-small;"><span><span style="color: #008080;">stats_name</span> <br /></span><span style="mso-spacerun: yes"><span style="color: #000000;"> </span></span><span><span style="color: #808080;">,</span></span><span><span style="color: #008080;">s2</span></span><span><span style="color: #808080;">.</span></span><span><span style="color: #008080;">stats_name</span></span><span style="color: #000000;"> </span><span><span style="color: #0000ff;">as</span></span><span style="color: #000000;"> </span></span></span><span style="font-family: Lucida Console;"><span style="font-size: x-small;"><span><span style="color: #008080;">identical_stats_name</span> <br /></span><span style="mso-spacerun: yes"><span style="color: #000000;"> </span></span><span><span style="color: #808080;">,</span></span><span><span style="color: #008080;">s2</span></span><span><span style="color: #808080;">.</span></span></span></span><span style="font-family: Lucida Console;"><span style="font-size: x-small;"><span><span style="color: #008080;">column_name</span> <br /></span><span style="mso-spacerun: yes"><span style="color: #000000;"> </span></span><span><span style="color: #0000ff;">from</span></span><span style="color: #000000;"> </span><span><span style="color: #008080;">all_stats</span></span><span style="color: #000000;"> </span><span><span style="color: #0000ff;">as</span></span><span style="color: #000000;"> </span></span></span><span style="font-family: Lucida Console;"><span style="font-size: x-small;"><span><span style="color: #008080;">s1</span> <br /></span><span style="mso-spacerun: yes"><span style="color: #000000;"> </span></span><span><span style="color: #808080;">inner</span></span><span style="color: #000000;"> </span><span><span style="color: #808080;">join</span></span><span style="color: #000000;"> </span><span><span style="color: #008080;">all_stats</span></span><span style="color: #000000;"> </span><span><span style="color: #0000ff;">as</span></span><span style="color: #000000;"> </span></span></span><span style="font-family: Lucida Console;"><span style="font-size: x-small;"><span><span style="color: #008080;">s2</span> <br /></span><span style="mso-spacerun: yes"><span style="color: #000000;"> </span></span><span><span style="color: #0000ff;">on</span></span><span style="color: #000000;"> </span><span><span style="color: #008080;">s1</span></span><span><span style="color: #808080;">.</span></span><span><span style="color: #ff00ff;">object_id</span></span><span style="color: #000000;"> </span><span><span style="color: #808080;">=</span></span><span style="color: #000000;"> </span><span><span style="color: #008080;">s2</span></span><span><span style="color: #808080;">.</span></span></span></span><span style="font-family: Lucida Console;"><span style="font-size: x-small;"><span><span style="color: #ff00ff;">object_id</span> <br /></span><span style="mso-spacerun: yes"><span style="color: #000000;"> </span></span><span><span style="color: #808080;">and</span></span><span style="color: #000000;"> </span><span><span style="color: #008080;">s1</span></span><span><span style="color: #808080;">.</span></span><span><span style="color: #008080;">stats_id</span></span><span style="color: #000000;"> </span><span><span style="color: #808080;">!=</span></span><span style="color: #000000;"> </span><span><span style="color: #008080;">s2</span></span><span><span style="color: #808080;">.</span></span></span></span><span style="font-family: Lucida Console;"><span style="font-size: x-small;"><span><span style="color: #008080;">stats_id</span> <br /></span><span style="mso-spacerun: yes"><span style="color: #000000;"> </span></span><span><span style="color: #808080;">and</span></span><span style="color: #000000;"> </span><span><span style="color: #008080;">s1</span></span><span><span style="color: #808080;">.</span></span><span><span style="color: #008080;">stats_column_id</span></span><span style="color: #000000;"> </span><span><span style="color: #808080;">=</span></span><span style="color: #000000;"> </span><span><span style="color: #008080;">s2</span></span><span><span style="color: #808080;">.</span></span></span></span><span style="font-family: Lucida Console;"><span style="font-size: x-small;"><span><span style="color: #008080;">stats_column_id</span> <br /></span><span style="mso-spacerun: yes"><span style="color: #000000;"> </span></span><span><span style="color: #808080;">and</span></span><span style="color: #000000;"> </span><span><span style="color: #008080;">s1</span></span><span><span style="color: #808080;">.</span></span><span><span style="color: #008080;">column_id</span></span><span style="color: #000000;"> </span><span><span style="color: #808080;">=</span></span><span style="color: #000000;"> </span><span><span style="color: #008080;">s2</span></span><span><span style="color: #808080;">.</span></span></span></span><span style="font-family: Lucida Console;"><span style="font-size: x-small;"><span><span style="color: #008080;">column_id</span> <br /></span><span style="mso-spacerun: yes"><span style="color: #000000;"> </span></span><span><span style="color: #808080;">and</span></span><span style="color: #000000;"> </span><span><span style="color: #008080;">s1</span></span><span><span style="color: #808080;">.</span></span><span><span style="color: #008080;">has_filter</span></span><span style="color: #000000;"> </span><span><span style="color: #808080;">=</span></span><span style="color: #000000;"> </span><span><span style="color: #008080;">s2</span></span><span><span style="color: #808080;">.</span></span></span></span><span style="font-family: Lucida Console;"><span style="font-size: x-small;"><span><span style="color: #008080;">has_filter</span> <br /></span><span style="mso-spacerun: yes"><span style="color: #000000;"> </span></span><span><span style="color: #808080;">and</span></span><span style="color: #000000;"> </span><span><span style="color: #008080;">s1</span></span><span><span style="color: #808080;">.</span></span><span><span style="color: #008080;">auto_created</span></span><span style="color: #000000;"> </span><span><span style="color: #808080;">!=</span></span><span style="color: #000000;"> </span><span><span style="color: #008080;">s2</span></span><span><span style="color: #808080;">.</span></span><span><span style="color: #008080;">auto_created</span></span></span></span></span></p>
</td>
</tr>
</tbody>
</table>
<p>With that query at hand, you may easily find redundant statistics. Here's a sample output:</p>
<p><a href="/blogs/media/blogs/holgerschmeling/windows-live-writer/611e11afab6f_113f3/image_4.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" src="/blogs/media/blogs/holgerschmeling/windows-live-writer/611e11afab6f_113f3/image_thumb_1.png" border="0" alt="image" width="790" height="66" /></a></p>
<p>If you'd like to find out more about SQL Server statistics, you may want to check out my series of two articles, published recently on the <a href="http://www.simple-talk.com">Simple-Talk</a> platform.</p>
<p>Part 1: <a href="http://www.simple-talk.com/sql/performance/queries,-damned-queries-and-statistics/">Queries, Damned Queries and Statistics</a> <br />Part 2: <a href="http://www.simple-talk.com/sql/performance/sql-server-statistics-problems-and-solutions/">SQL Server Statistics: Problems and Solutions</a></p>
<p>It's free, so you might want to give it a try. Feel free to vote, if you like it!</p>]]></content:encoded>
								<comments>https://www.insidesql.org/blogs/holgerschmeling/2010/11/04/multiple-statistics-sharing-the-same-leading-column#comments</comments>
			<wfw:commentRss>https://www.insidesql.org/blogs/holgerschmeling/?tempskin=_rss2&#38;disp=comments&#38;p=1738</wfw:commentRss>
		</item>
				<item>
			<title>Did you know: Aggregate functions on floats may be non-deterministic</title>
			<link>https://www.insidesql.org/blogs/holgerschmeling/2010/11/02/did-you-know-aggregate-functions-on-floats-may-be-non-deterministic</link>
			<pubDate>Tue, 02 Nov 2010 17:57:49 +0000</pubDate>			<dc:creator>Holger Schmeling</dc:creator>
			<category domain="main">SQL Server Performance</category>
<category domain="alt">SQL Server Tips</category>			<guid isPermaLink="false">1718@https://www.insidesql.org/blogs/</guid>
						<description>&lt;p&gt;One day some of the report-users mentioned that, every time they run a report, they get different results. My first idea was that there were some undergoing data changes, probably from a different connection/user, so this would explain it. But it turned out that no modifications were made. Even setting the database to read only did not help. Numbers in reports differed by about 20% with every execution.&lt;/p&gt;
&lt;p&gt;Delving into it, I could isolate the problem. It was a single SELECT statement that, when invoked, returned different results. The numbers differed by up to 20% in value without any data changes being performed!&lt;/p&gt;
&lt;p&gt;Have a look at the following sample. We create a test table to demonstrate what I&#039;m talking about:&lt;/p&gt;
&lt;table class=&quot;MsoTableGrid&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8eb4e3; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8eb4e3; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102&quot; border=&quot;1&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;&gt;
&lt;tbody&gt;
&lt;tr style=&quot;mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes&quot;&gt;
&lt;td style=&quot;border: 1pt dashed #8eb4e3; padding: 0in 5.4pt; width: 678.75pt;&quot; width=&quot;905&quot; valign=&quot;top&quot;&gt;
&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin: 6pt 0in&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Lucida Console&amp;quot;; color: blue; font-size: 12pt; mso-bidi-font-family: &#039;Times New Roman&#039;; mso-no-proof: yes; mso-ansi-language: en-us&quot; lang=&quot;EN-US&quot;&gt;use&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Lucida Console&amp;quot;; font-size: 12pt; mso-bidi-font-family: &#039;Times New Roman&#039;; mso-no-proof: yes; mso-ansi-language: en-us&quot; lang=&quot;EN-US&quot;&gt; tempdb              &lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;go                &lt;br /&gt; &lt;br /&gt;if &lt;/span&gt;&lt;span style=&quot;color: gray&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: fuchsia&quot;&gt;object_id&lt;/span&gt;&lt;span style=&quot;color: gray&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: red&quot;&gt;&#039;SumTest&#039;&lt;/span&gt;&lt;span style=&quot;color: gray&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: red&quot;&gt;&#039;U&#039;&lt;/span&gt;&lt;span style=&quot;color: gray&quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color: gray&quot;&gt;is&lt;/span&gt; &lt;span style=&quot;color: gray&quot;&gt;not&lt;/span&gt; &lt;span style=&quot;color: gray&quot;&gt;null)                &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: blue&quot;&gt;drop&lt;/span&gt; &lt;span style=&quot;color: blue&quot;&gt;table&lt;/span&gt; SumTest               &lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;go&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt; &lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;create&lt;/span&gt; &lt;span style=&quot;color: blue&quot;&gt;table&lt;/span&gt; SumTest               &lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: gray&quot;&gt;(                &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;floatVal &lt;span style=&quot;color: blue&quot;&gt;float&lt;/span&gt; &lt;span style=&quot;color: gray&quot;&gt;not&lt;/span&gt; &lt;span style=&quot;color: gray&quot;&gt;null                &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: gray&quot;&gt;,&lt;/span&gt;decimalVal &lt;span style=&quot;color: blue&quot;&gt;decimal&lt;/span&gt;&lt;span style=&quot;color: gray&quot;&gt;(&lt;/span&gt;20&lt;span style=&quot;color: gray&quot;&gt;,&lt;/span&gt;4&lt;span style=&quot;color: gray&quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color: gray&quot;&gt;not&lt;/span&gt; &lt;span style=&quot;color: gray&quot;&gt;null                &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: gray&quot;&gt;,&lt;/span&gt;filler &lt;span style=&quot;color: blue&quot;&gt;nchar&lt;/span&gt;&lt;span style=&quot;color: gray&quot;&gt;(&lt;/span&gt;300&lt;span style=&quot;color: gray&quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color: gray&quot;&gt;not&lt;/span&gt; &lt;span style=&quot;color: gray&quot;&gt;null&lt;/span&gt; &lt;span style=&quot;color: blue&quot;&gt;default&lt;/span&gt; &lt;span style=&quot;color: red&quot;&gt;&#039;#&#039;                &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Lucida Console&amp;quot;; color: gray; font-size: 12pt; mso-bidi-font-family: &#039;Times New Roman&#039;; mso-no-proof: yes&quot;&gt;)              &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Lucida Console&amp;quot;; color: blue; font-size: 12pt; mso-bidi-font-family: &#039;Times New Roman&#039;; mso-no-proof: yes&quot;&gt;go&lt;/span&gt;&lt;span style=&quot;mso-ansi-language: en-us&quot; lang=&quot;EN-US&quot;&gt; &lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;The table has three columns, where the third column only serves the purpose of filling up the row, so the table contains more data pages.&lt;/p&gt;
&lt;p&gt;Let&#039;s now insert 600000 rows into our table:&lt;/p&gt;
&lt;table class=&quot;MsoTableGrid&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8eb4e3; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8eb4e3; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102&quot; border=&quot;1&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;&gt;
&lt;tbody&gt;
&lt;tr style=&quot;mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes&quot;&gt;
&lt;td style=&quot;border: 1pt dashed #8eb4e3; padding: 0in 5.4pt; width: 678.75pt;&quot; width=&quot;905&quot; valign=&quot;top&quot;&gt;
&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin: 6pt 0in; mso-layout-grid-align: none&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Lucida Console&amp;quot;; color: blue; font-size: 12pt; mso-bidi-font-family: &#039;Times New Roman&#039;; mso-no-proof: yes; mso-ansi-language: en-us&quot; lang=&quot;EN-US&quot;&gt;declare&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Lucida Console&amp;quot;; font-size: 12pt; mso-bidi-font-family: &#039;Times New Roman&#039;; mso-no-proof: yes; mso-ansi-language: en-us&quot; lang=&quot;EN-US&quot;&gt; @x &lt;span style=&quot;color: blue&quot;&gt;float                &lt;br /&gt;set&lt;/span&gt; @x &lt;span style=&quot;color: gray&quot;&gt;=&lt;/span&gt; 1000000000000000.9999&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt; &lt;br /&gt; &lt;br /&gt;&lt;span style=&quot;color: green&quot;&gt;-- Insert 300000 identical rows                &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: blue&quot;&gt;insert&lt;/span&gt; SumTest&lt;span style=&quot;color: gray&quot;&gt;(&lt;/span&gt;floatVal&lt;span style=&quot;color: gray&quot;&gt;,&lt;/span&gt; decimalVal&lt;span style=&quot;color: gray&quot;&gt;)                &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: blue&quot;&gt;select&lt;/span&gt; &lt;span style=&quot;color: blue&quot;&gt;top&lt;/span&gt;&lt;span style=&quot;color: gray&quot;&gt;(&lt;/span&gt;300000&lt;span style=&quot;color: gray&quot;&gt;)&lt;/span&gt; @x&lt;span style=&quot;color: gray&quot;&gt;,&lt;/span&gt; @x               &lt;br /&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: blue&quot;&gt;from&lt;/span&gt; &lt;span style=&quot;color: green&quot;&gt;sys&lt;/span&gt;&lt;span style=&quot;color: gray&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: green&quot;&gt;trace_event_bindings&lt;/span&gt; &lt;span style=&quot;color: blue&quot;&gt;as&lt;/span&gt; b1               &lt;br /&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: gray&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: green&quot;&gt;sys&lt;/span&gt;&lt;span style=&quot;color: gray&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: green&quot;&gt;trace_event_bindings&lt;/span&gt; &lt;span style=&quot;color: blue&quot;&gt;as&lt;/span&gt; b2               &lt;br /&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt; &lt;br /&gt;&lt;span style=&quot;color: green&quot;&gt;-- Again insert 300000 rows.                &lt;br /&gt;-- This time with negative sign                 &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: blue&quot;&gt;insert&lt;/span&gt; SumTest&lt;span style=&quot;color: gray&quot;&gt;(&lt;/span&gt;floatVal&lt;span style=&quot;color: gray&quot;&gt;,&lt;/span&gt; decimalVal&lt;span style=&quot;color: gray&quot;&gt;)                &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: blue&quot;&gt;select&lt;/span&gt; &lt;span style=&quot;color: blue&quot;&gt;top&lt;/span&gt;&lt;span style=&quot;color: gray&quot;&gt;(&lt;/span&gt;300000&lt;span style=&quot;color: gray&quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color: gray&quot;&gt;-&lt;/span&gt;@x&lt;span style=&quot;color: gray&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: gray&quot;&gt;-&lt;/span&gt;@x               &lt;br /&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: blue&quot;&gt;from&lt;/span&gt; &lt;span style=&quot;color: green&quot;&gt;sys&lt;/span&gt;&lt;span style=&quot;color: gray&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: green&quot;&gt;trace_event_bindings&lt;/span&gt; &lt;span style=&quot;color: blue&quot;&gt;as&lt;/span&gt; b1               &lt;br /&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: gray&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: green&quot;&gt;sys&lt;/span&gt;&lt;span style=&quot;color: gray&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: green&quot;&gt;trace_event_bindings&lt;/span&gt; &lt;span style=&quot;color: blue&quot;&gt;as&lt;/span&gt; b2&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;The first INSERT statement adds 300000 rows with positive values for the two columns floatVal and decimalVal. After that, we insert another 300000 rows, this time with inverse signs. So in total, values for each of the two columns should add up to zero. Let&#039;s check this by invoking the summation over all rows a few times:&lt;/p&gt;
&lt;table class=&quot;MsoTableGrid&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8eb4e3; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8eb4e3; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102&quot; border=&quot;1&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;&gt;
&lt;tbody&gt;
&lt;tr style=&quot;mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes&quot;&gt;
&lt;td style=&quot;border: 1pt dashed #8eb4e3; padding: 0in 5.4pt; width: 678.75pt;&quot; width=&quot;905&quot; valign=&quot;top&quot;&gt;
&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin: 6pt 0in; mso-layout-grid-align: none&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Lucida Console&amp;quot;; color: blue; font-size: 12pt; mso-bidi-font-family: &#039;Times New Roman&#039;; mso-no-proof: yes; mso-ansi-language: en-us&quot; lang=&quot;EN-US&quot;&gt;select&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Lucida Console&amp;quot;; font-size: 12pt; mso-bidi-font-family: &#039;Times New Roman&#039;; mso-no-proof: yes; mso-ansi-language: en-us&quot; lang=&quot;EN-US&quot;&gt; &lt;span style=&quot;color: fuchsia&quot;&gt;sum&lt;/span&gt;&lt;span style=&quot;color: gray&quot;&gt;(&lt;/span&gt;floatVal&lt;span style=&quot;color: gray&quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color: blue&quot;&gt;as&lt;/span&gt; SumFloatVal               &lt;br /&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: gray&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: fuchsia&quot;&gt;sum&lt;/span&gt;&lt;span style=&quot;color: gray&quot;&gt;(&lt;/span&gt;decimalVal&lt;span style=&quot;color: gray&quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color: blue&quot;&gt;as&lt;/span&gt; SumDecimalVal               &lt;br /&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: blue&quot;&gt;from&lt;/span&gt; SumTest               &lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;union&lt;/span&gt; &lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;select&lt;/span&gt; &lt;span style=&quot;color: fuchsia&quot;&gt;sum&lt;/span&gt;&lt;span style=&quot;color: gray&quot;&gt;(&lt;/span&gt;floatVal&lt;span style=&quot;color: gray&quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color: blue&quot;&gt;as&lt;/span&gt; SumFloatVal               &lt;br /&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: gray&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: fuchsia&quot;&gt;sum&lt;/span&gt;&lt;span style=&quot;color: gray&quot;&gt;(&lt;/span&gt;decimalVal&lt;span style=&quot;color: gray&quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color: blue&quot;&gt;as&lt;/span&gt; SumDecimalVal               &lt;br /&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: blue&quot;&gt;from&lt;/span&gt; SumTest               &lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;union&lt;/span&gt; &lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;select&lt;/span&gt; &lt;span style=&quot;color: fuchsia&quot;&gt;sum&lt;/span&gt;&lt;span style=&quot;color: gray&quot;&gt;(&lt;/span&gt;floatVal&lt;span style=&quot;color: gray&quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color: blue&quot;&gt;as&lt;/span&gt; SumFloatVal               &lt;br /&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: gray&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: fuchsia&quot;&gt;sum&lt;/span&gt;&lt;span style=&quot;color: gray&quot;&gt;(&lt;/span&gt;decimalVal&lt;span style=&quot;color: gray&quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color: blue&quot;&gt;as&lt;/span&gt; SumDecimalVal               &lt;br /&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: blue&quot;&gt;from&lt;/span&gt; SumTest               &lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;union&lt;/span&gt; &lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;select&lt;/span&gt; &lt;span style=&quot;color: fuchsia&quot;&gt;sum&lt;/span&gt;&lt;span style=&quot;color: gray&quot;&gt;(&lt;/span&gt;floatVal&lt;span style=&quot;color: gray&quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color: blue&quot;&gt;as&lt;/span&gt; SumFloatVal               &lt;br /&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: gray&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: fuchsia&quot;&gt;sum&lt;/span&gt;&lt;span style=&quot;color: gray&quot;&gt;(&lt;/span&gt;decimalVal&lt;span style=&quot;color: gray&quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color: blue&quot;&gt;as&lt;/span&gt; SumDecimalVal               &lt;br /&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: blue&quot;&gt;from&lt;/span&gt; SumTest               &lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;union&lt;/span&gt; &lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;select&lt;/span&gt; &lt;span style=&quot;color: fuchsia&quot;&gt;sum&lt;/span&gt;&lt;span style=&quot;color: gray&quot;&gt;(&lt;/span&gt;floatVal&lt;span style=&quot;color: gray&quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color: blue&quot;&gt;as&lt;/span&gt; SumFloatVal               &lt;br /&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: gray&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: fuchsia&quot;&gt;sum&lt;/span&gt;&lt;span style=&quot;color: gray&quot;&gt;(&lt;/span&gt;decimalVal&lt;span style=&quot;color: gray&quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color: blue&quot;&gt;as&lt;/span&gt; SumDecimalVal               &lt;br /&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: blue&quot;&gt;from&lt;/span&gt; SumTest               &lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;union&lt;/span&gt; &lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;select&lt;/span&gt; &lt;span style=&quot;color: fuchsia&quot;&gt;sum&lt;/span&gt;&lt;span style=&quot;color: gray&quot;&gt;(&lt;/span&gt;floatVal&lt;span style=&quot;color: gray&quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color: blue&quot;&gt;as&lt;/span&gt; SumFloatVal               &lt;br /&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: gray&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: fuchsia&quot;&gt;sum&lt;/span&gt;&lt;span style=&quot;color: gray&quot;&gt;(&lt;/span&gt;decimalVal&lt;span style=&quot;color: gray&quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color: blue&quot;&gt;as&lt;/span&gt; SumDecimalVal               &lt;br /&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: blue&quot;&gt;from&lt;/span&gt; SumTest               &lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;union&lt;/span&gt; &lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;select&lt;/span&gt; &lt;span style=&quot;color: fuchsia&quot;&gt;sum&lt;/span&gt;&lt;span style=&quot;color: gray&quot;&gt;(&lt;/span&gt;floatVal&lt;span style=&quot;color: gray&quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color: blue&quot;&gt;as&lt;/span&gt; SumFloatVal               &lt;br /&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: gray&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: fuchsia&quot;&gt;sum&lt;/span&gt;&lt;span style=&quot;color: gray&quot;&gt;(&lt;/span&gt;decimalVal&lt;span style=&quot;color: gray&quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color: blue&quot;&gt;as&lt;/span&gt; SumDecimalVal               &lt;br /&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: blue&quot;&gt;from&lt;/span&gt; SumTest               &lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;union&lt;/span&gt; &lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;select&lt;/span&gt; &lt;span style=&quot;color: fuchsia&quot;&gt;sum&lt;/span&gt;&lt;span style=&quot;color: gray&quot;&gt;(&lt;/span&gt;floatVal&lt;span style=&quot;color: gray&quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color: blue&quot;&gt;as&lt;/span&gt; SumFloatVal               &lt;br /&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: gray&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: fuchsia&quot;&gt;sum&lt;/span&gt;&lt;span style=&quot;color: gray&quot;&gt;(&lt;/span&gt;decimalVal&lt;span style=&quot;color: gray&quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color: blue&quot;&gt;as&lt;/span&gt; SumDecimalVal               &lt;br /&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: blue&quot;&gt;from&lt;/span&gt; SumTest               &lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;union&lt;/span&gt; &lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;select&lt;/span&gt; &lt;span style=&quot;color: fuchsia&quot;&gt;sum&lt;/span&gt;&lt;span style=&quot;color: gray&quot;&gt;(&lt;/span&gt;floatVal&lt;span style=&quot;color: gray&quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color: blue&quot;&gt;as&lt;/span&gt; SumFloatVal               &lt;br /&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Lucida Console&amp;quot;; color: gray; font-size: 12pt; mso-bidi-font-family: &#039;Times New Roman&#039;; mso-no-proof: yes&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Lucida Console&amp;quot;; color: fuchsia; font-size: 12pt; mso-bidi-font-family: &#039;Times New Roman&#039;; mso-no-proof: yes&quot;&gt;sum&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Lucida Console&amp;quot;; color: gray; font-size: 12pt; mso-bidi-font-family: &#039;Times New Roman&#039;; mso-no-proof: yes&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Lucida Console&amp;quot;; font-size: 12pt; mso-bidi-font-family: &#039;Times New Roman&#039;; mso-no-proof: yes&quot;&gt;decimalVal&lt;span style=&quot;color: gray&quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color: blue&quot;&gt;as&lt;/span&gt; SumDecimalVal               &lt;br /&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: blue&quot;&gt;from&lt;/span&gt; SumTest&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Lucida Console&amp;quot;; font-size: 12pt; mso-bidi-font-family: &#039;Times New Roman&#039;; mso-no-proof: yes; mso-ansi-language: en-us&quot; lang=&quot;EN-US&quot;&gt; &lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;And here&#039;s the result:&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://lh5.ggpht.com/_-C4uSahz1Gg/S31vxEDbZqI/AAAAAAAABcg/y5viS3JM5as/s1600-h/image%5B7%5D.png&quot;&gt;&lt;img style=&quot;border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px&quot; title=&quot;image&quot; src=&quot;http://lh4.ggpht.com/_-C4uSahz1Gg/S31vxlxQ7BI/AAAAAAAABck/RMH3Br1F6lg/image_thumb%5B7%5D.png?imgmax=800&quot; border=&quot;0&quot; alt=&quot;image&quot; width=&quot;295&quot; height=&quot;172&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;As for the DECIMAL column, the outcome is as expected. But look at the totals for the FLOAT column. It&#039;s perfectly understandable, the sum will reveal some rounding errors. What really puzzled me is the difference between the numbers. Why isn&#039;t the rounding error the same for all executions?&lt;/p&gt;
&lt;p&gt;I was pretty sure that I discovered a bug in SQL Server and posted a regarding item on MSFT&#039;s connect platform (see &lt;a href=&quot;https://connect.microsoft.com/SQLServer/feedback/details/465147/select-sum-is-non-deterministic-when-adding-the-column-values-of-datatype-float&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;Unfortunately nobody cared about my problem, and so I took the opportunity of talking to some fellows of the SQL Server CAT team on the occasion of the 2009 PASS Summit. After a while, I received an explanation which I&#039;d like to repeat here.&lt;/p&gt;
&lt;p&gt;The query is executed in parallel, as the plan reveals:&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://lh3.ggpht.com/_-C4uSahz1Gg/S31vyk37WKI/AAAAAAAABco/F0U8x6VjF-w/s1600-h/image1%5B1%5D.png&quot;&gt;&lt;img style=&quot;border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px&quot; title=&quot;image&quot; src=&quot;http://lh4.ggpht.com/_-C4uSahz1Gg/S31vz8UvHoI/AAAAAAAABcs/IBL6nCIgdGU/image1_thumb.png?imgmax=800&quot; border=&quot;0&quot; alt=&quot;image&quot; width=&quot;982&quot; height=&quot;87&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;When summing up values, usually the summation sequence doesn&#039;t matter. (If you remember some mathematics from school that&#039;s what the commutative law of addition is about). Therefore, reading values in multiple threads and adding up the values in any arbitrary order is perfect, as the order doesn&#039;t have any influence on the result. Well, at least theoretically. When adding float values, there&#039;s floating point arithmetic rounding errors with every addition. These added-up rounding errors are the reason for the non-zero values of the float totals in our example. So that&#039;s ok, but why different results with almost every execution? The reason for this is parallel execution. Added-up rounding errors &lt;em&gt;depend&lt;/em&gt; on the sequence, so the commutative law does not really apply to these errors. There&#039;s a chance that the sequence of rows changes with every execution, if the query is executed in parallel. And that&#039;s why the results change, dependent only on some butterfly wing movements at the other side of the world.&lt;/p&gt;
&lt;p&gt;If we add the MAXDOP 1 query hint, only one thread is utilized and the results are the same for every execution, although rounding errors still remain present. So this query:&lt;/p&gt;
&lt;table class=&quot;MsoTableGrid&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8eb4e3; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8eb4e3; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102&quot; border=&quot;1&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;&gt;
&lt;tbody&gt;
&lt;tr style=&quot;mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes&quot;&gt;
&lt;td style=&quot;border: 1pt dashed #8eb4e3; padding: 0in 5.4pt; width: 678.75pt;&quot; width=&quot;905&quot; valign=&quot;top&quot;&gt;
&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin: 6pt 0in; mso-layout-grid-align: none&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Lucida Console&amp;quot;; color: blue; font-size: 12pt; mso-bidi-font-family: &#039;Times New Roman&#039;; mso-no-proof: yes; mso-ansi-language: en-us&quot; lang=&quot;EN-US&quot;&gt;select&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Lucida Console&amp;quot;; font-size: 12pt; mso-bidi-font-family: &#039;Times New Roman&#039;; mso-no-proof: yes; mso-ansi-language: en-us&quot; lang=&quot;EN-US&quot;&gt; &lt;span style=&quot;color: fuchsia&quot;&gt;sum&lt;/span&gt;&lt;span style=&quot;color: gray&quot;&gt;(&lt;/span&gt;floatVal&lt;span style=&quot;color: gray&quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color: blue&quot;&gt;as&lt;/span&gt; SumFloatVal               &lt;br /&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: gray&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: fuchsia&quot;&gt;sum&lt;/span&gt;&lt;span style=&quot;color: gray&quot;&gt;(&lt;/span&gt;decimalVal&lt;span style=&quot;color: gray&quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color: blue&quot;&gt;as&lt;/span&gt; SumDecimalVal               &lt;br /&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: blue&quot;&gt;from&lt;/span&gt; SumTest &lt;span style=&quot;color: blue&quot;&gt;option &lt;/span&gt;&lt;span style=&quot;color: gray&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: blue&quot;&gt;maxdop&lt;/span&gt; 1&lt;span style=&quot;color: gray&quot;&gt;)&lt;/span&gt; &lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;will be executed by using the following (single thread) execution plan:&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://lh6.ggpht.com/_-C4uSahz1Gg/S31v040xHTI/AAAAAAAABcw/S3sP1BqTx8c/s1600-h/image7%5B1%5D.png&quot;&gt;&lt;img style=&quot;border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px&quot; title=&quot;image&quot; src=&quot;http://lh3.ggpht.com/_-C4uSahz1Gg/S31v3V9wRDI/AAAAAAAABc4/nu24EdZdhyE/image7_thumb.png?imgmax=800&quot; border=&quot;0&quot; alt=&quot;image&quot; width=&quot;511&quot; height=&quot;85&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;This time the result (and also the rounding error) is always the same.&lt;/p&gt;
&lt;p&gt;Pretty soon after delivering the explanation, the bug was closed. Reason: the observed behavior is &quot;by design&quot;.&lt;/p&gt;
&lt;p&gt;I can understand that the problem originates from computer resp. processor architecture and MSFT has no chance of control therefore.&lt;/p&gt;
&lt;p&gt;Although.&lt;/p&gt;
&lt;p&gt;When using SSAS&#039; write back functionality, SSAS will always create numeric columns of FLOAT data types. There&#039;s no chance of manipulating the data type; it&#039;s &lt;em&gt;always&lt;/em&gt; float!&lt;/p&gt;
&lt;p&gt;Additionally, SSAS more often than not inserts rows into write back tables with vastly large resp. small values. When looking an these rows, it appeared that they are created solely with the intention of summing up to zero. We discovered plenty of these rows containing inverse values that usually should nullify in total, but apparently don&#039;t. By the way that&#039;s why closing the bug with the &quot;By Design&quot; explanation makes me somewhat sad.&lt;/p&gt;
&lt;p&gt;So, probably avoiding FLOATs is a good idea! Unfortunately, this is simply not possible in all cases and sometimes out of our control.&lt;/p&gt;</description>
			<content:encoded><![CDATA[<p>One day some of the report-users mentioned that, every time they run a report, they get different results. My first idea was that there were some undergoing data changes, probably from a different connection/user, so this would explain it. But it turned out that no modifications were made. Even setting the database to read only did not help. Numbers in reports differed by about 20% with every execution.</p>
<p>Delving into it, I could isolate the problem. It was a single SELECT statement that, when invoked, returned different results. The numbers differed by up to 20% in value without any data changes being performed!</p>
<p>Have a look at the following sample. We create a test table to demonstrate what I'm talking about:</p>
<table class="MsoTableGrid" style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8eb4e3; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8eb4e3; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes">
<td style="border: 1pt dashed #8eb4e3; padding: 0in 5.4pt; width: 678.75pt;" width="905" valign="top">
<p class="MsoNormal" style="line-height: normal; margin: 6pt 0in"><span style="font-family: &quot;Lucida Console&quot;; color: blue; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes; mso-ansi-language: en-us" lang="EN-US">use</span><span style="font-family: &quot;Lucida Console&quot;; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes; mso-ansi-language: en-us" lang="EN-US"> tempdb              <br /><span style="color: blue">go                <br /> <br />if </span><span style="color: gray">(</span><span style="color: fuchsia">object_id</span><span style="color: gray">(</span><span style="color: red">'SumTest'</span><span style="color: gray">,</span> <span style="color: red">'U'</span><span style="color: gray">)</span> <span style="color: gray">is</span> <span style="color: gray">not</span> <span style="color: gray">null)                <br /></span><span style="mso-spacerun: yes"> </span><span style="color: blue">drop</span> <span style="color: blue">table</span> SumTest               <br /><span style="color: blue">go</span><span style="mso-spacerun: yes"> </span> <br /><span style="color: blue">create</span> <span style="color: blue">table</span> SumTest               <br /><span style="color: blue"><span style="mso-spacerun: yes"> </span></span><span style="color: gray">(                <br /></span><span style="mso-spacerun: yes"> </span>floatVal <span style="color: blue">float</span> <span style="color: gray">not</span> <span style="color: gray">null                <br /></span><span style="mso-spacerun: yes"> </span><span style="color: gray">,</span>decimalVal <span style="color: blue">decimal</span><span style="color: gray">(</span>20<span style="color: gray">,</span>4<span style="color: gray">)</span> <span style="color: gray">not</span> <span style="color: gray">null                <br /></span><span style="mso-spacerun: yes"> </span><span style="color: gray">,</span>filler <span style="color: blue">nchar</span><span style="color: gray">(</span>300<span style="color: gray">)</span> <span style="color: gray">not</span> <span style="color: gray">null</span> <span style="color: blue">default</span> <span style="color: red">'#'                <br /></span><span style="mso-spacerun: yes"> </span></span><span style="font-family: &quot;Lucida Console&quot;; color: gray; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">)              <br /></span><span style="font-family: &quot;Lucida Console&quot;; color: blue; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">go</span><span style="mso-ansi-language: en-us" lang="EN-US"> </span></p>
</td>
</tr>
</tbody>
</table>
<p>The table has three columns, where the third column only serves the purpose of filling up the row, so the table contains more data pages.</p>
<p>Let's now insert 600000 rows into our table:</p>
<table class="MsoTableGrid" style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8eb4e3; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8eb4e3; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes">
<td style="border: 1pt dashed #8eb4e3; padding: 0in 5.4pt; width: 678.75pt;" width="905" valign="top">
<p class="MsoNormal" style="line-height: normal; margin: 6pt 0in; mso-layout-grid-align: none"><span style="font-family: &quot;Lucida Console&quot;; color: blue; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes; mso-ansi-language: en-us" lang="EN-US">declare</span><span style="font-family: &quot;Lucida Console&quot;; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes; mso-ansi-language: en-us" lang="EN-US"> @x <span style="color: blue">float                <br />set</span> @x <span style="color: gray">=</span> 1000000000000000.9999<span style="mso-spacerun: yes"> </span> <br /> <br /><span style="color: green">-- Insert 300000 identical rows                <br /></span><span style="color: blue">insert</span> SumTest<span style="color: gray">(</span>floatVal<span style="color: gray">,</span> decimalVal<span style="color: gray">)                <br /></span><span style="mso-spacerun: yes"> </span><span style="color: blue">select</span> <span style="color: blue">top</span><span style="color: gray">(</span>300000<span style="color: gray">)</span> @x<span style="color: gray">,</span> @x               <br /><span style="mso-spacerun: yes"> </span><span style="color: blue">from</span> <span style="color: green">sys</span><span style="color: gray">.</span><span style="color: green">trace_event_bindings</span> <span style="color: blue">as</span> b1               <br /><span style="mso-spacerun: yes"> </span><span style="color: gray">,</span><span style="color: green">sys</span><span style="color: gray">.</span><span style="color: green">trace_event_bindings</span> <span style="color: blue">as</span> b2               <br /><span style="mso-spacerun: yes"> </span> <br /><span style="color: green">-- Again insert 300000 rows.                <br />-- This time with negative sign                 <br /></span><span style="color: blue">insert</span> SumTest<span style="color: gray">(</span>floatVal<span style="color: gray">,</span> decimalVal<span style="color: gray">)                <br /></span><span style="mso-spacerun: yes"> </span><span style="color: blue">select</span> <span style="color: blue">top</span><span style="color: gray">(</span>300000<span style="color: gray">)</span> <span style="color: gray">-</span>@x<span style="color: gray">,</span> <span style="color: gray">-</span>@x               <br /><span style="mso-spacerun: yes"> </span><span style="color: blue">from</span> <span style="color: green">sys</span><span style="color: gray">.</span><span style="color: green">trace_event_bindings</span> <span style="color: blue">as</span> b1               <br /><span style="mso-spacerun: yes"> </span><span style="color: gray">,</span><span style="color: green">sys</span><span style="color: gray">.</span><span style="color: green">trace_event_bindings</span> <span style="color: blue">as</span> b2</span></p>
</td>
</tr>
</tbody>
</table>
<p>The first INSERT statement adds 300000 rows with positive values for the two columns floatVal and decimalVal. After that, we insert another 300000 rows, this time with inverse signs. So in total, values for each of the two columns should add up to zero. Let's check this by invoking the summation over all rows a few times:</p>
<table class="MsoTableGrid" style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8eb4e3; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8eb4e3; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes">
<td style="border: 1pt dashed #8eb4e3; padding: 0in 5.4pt; width: 678.75pt;" width="905" valign="top">
<p class="MsoNormal" style="line-height: normal; margin: 6pt 0in; mso-layout-grid-align: none"><span style="font-family: &quot;Lucida Console&quot;; color: blue; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes; mso-ansi-language: en-us" lang="EN-US">select</span><span style="font-family: &quot;Lucida Console&quot;; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes; mso-ansi-language: en-us" lang="EN-US"> <span style="color: fuchsia">sum</span><span style="color: gray">(</span>floatVal<span style="color: gray">)</span> <span style="color: blue">as</span> SumFloatVal               <br /><span style="mso-spacerun: yes"> </span><span style="color: gray">,</span><span style="color: fuchsia">sum</span><span style="color: gray">(</span>decimalVal<span style="color: gray">)</span> <span style="color: blue">as</span> SumDecimalVal               <br /><span style="mso-spacerun: yes"> </span><span style="color: blue">from</span> SumTest               <br /><span style="color: blue">union</span> <br /><span style="color: blue">select</span> <span style="color: fuchsia">sum</span><span style="color: gray">(</span>floatVal<span style="color: gray">)</span> <span style="color: blue">as</span> SumFloatVal               <br /><span style="mso-spacerun: yes"> </span><span style="color: gray">,</span><span style="color: fuchsia">sum</span><span style="color: gray">(</span>decimalVal<span style="color: gray">)</span> <span style="color: blue">as</span> SumDecimalVal               <br /><span style="mso-spacerun: yes"> </span><span style="color: blue">from</span> SumTest               <br /><span style="color: blue">union</span> <br /><span style="color: blue">select</span> <span style="color: fuchsia">sum</span><span style="color: gray">(</span>floatVal<span style="color: gray">)</span> <span style="color: blue">as</span> SumFloatVal               <br /><span style="mso-spacerun: yes"> </span><span style="color: gray">,</span><span style="color: fuchsia">sum</span><span style="color: gray">(</span>decimalVal<span style="color: gray">)</span> <span style="color: blue">as</span> SumDecimalVal               <br /><span style="mso-spacerun: yes"> </span><span style="color: blue">from</span> SumTest               <br /><span style="color: blue">union</span> <br /><span style="color: blue">select</span> <span style="color: fuchsia">sum</span><span style="color: gray">(</span>floatVal<span style="color: gray">)</span> <span style="color: blue">as</span> SumFloatVal               <br /><span style="mso-spacerun: yes"> </span><span style="color: gray">,</span><span style="color: fuchsia">sum</span><span style="color: gray">(</span>decimalVal<span style="color: gray">)</span> <span style="color: blue">as</span> SumDecimalVal               <br /><span style="mso-spacerun: yes"> </span><span style="color: blue">from</span> SumTest               <br /><span style="color: blue">union</span> <br /><span style="color: blue">select</span> <span style="color: fuchsia">sum</span><span style="color: gray">(</span>floatVal<span style="color: gray">)</span> <span style="color: blue">as</span> SumFloatVal               <br /><span style="mso-spacerun: yes"> </span><span style="color: gray">,</span><span style="color: fuchsia">sum</span><span style="color: gray">(</span>decimalVal<span style="color: gray">)</span> <span style="color: blue">as</span> SumDecimalVal               <br /><span style="mso-spacerun: yes"> </span><span style="color: blue">from</span> SumTest               <br /><span style="color: blue">union</span> <br /><span style="color: blue">select</span> <span style="color: fuchsia">sum</span><span style="color: gray">(</span>floatVal<span style="color: gray">)</span> <span style="color: blue">as</span> SumFloatVal               <br /><span style="mso-spacerun: yes"> </span><span style="color: gray">,</span><span style="color: fuchsia">sum</span><span style="color: gray">(</span>decimalVal<span style="color: gray">)</span> <span style="color: blue">as</span> SumDecimalVal               <br /><span style="mso-spacerun: yes"> </span><span style="color: blue">from</span> SumTest               <br /><span style="color: blue">union</span> <br /><span style="color: blue">select</span> <span style="color: fuchsia">sum</span><span style="color: gray">(</span>floatVal<span style="color: gray">)</span> <span style="color: blue">as</span> SumFloatVal               <br /><span style="mso-spacerun: yes"> </span><span style="color: gray">,</span><span style="color: fuchsia">sum</span><span style="color: gray">(</span>decimalVal<span style="color: gray">)</span> <span style="color: blue">as</span> SumDecimalVal               <br /><span style="mso-spacerun: yes"> </span><span style="color: blue">from</span> SumTest               <br /><span style="color: blue">union</span> <br /><span style="color: blue">select</span> <span style="color: fuchsia">sum</span><span style="color: gray">(</span>floatVal<span style="color: gray">)</span> <span style="color: blue">as</span> SumFloatVal               <br /><span style="mso-spacerun: yes"> </span><span style="color: gray">,</span><span style="color: fuchsia">sum</span><span style="color: gray">(</span>decimalVal<span style="color: gray">)</span> <span style="color: blue">as</span> SumDecimalVal               <br /><span style="mso-spacerun: yes"> </span><span style="color: blue">from</span> SumTest               <br /><span style="color: blue">union</span> <br /><span style="color: blue">select</span> <span style="color: fuchsia">sum</span><span style="color: gray">(</span>floatVal<span style="color: gray">)</span> <span style="color: blue">as</span> SumFloatVal               <br /><span style="mso-spacerun: yes"> </span></span><span style="font-family: &quot;Lucida Console&quot;; color: gray; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">,</span><span style="font-family: &quot;Lucida Console&quot;; color: fuchsia; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">sum</span><span style="font-family: &quot;Lucida Console&quot;; color: gray; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">(</span><span style="font-family: &quot;Lucida Console&quot;; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">decimalVal<span style="color: gray">)</span> <span style="color: blue">as</span> SumDecimalVal               <br /><span style="mso-spacerun: yes"> </span><span style="color: blue">from</span> SumTest</span><span style="font-family: &quot;Lucida Console&quot;; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes; mso-ansi-language: en-us" lang="EN-US"> </span></p>
</td>
</tr>
</tbody>
</table>
<p>And here's the result:</p>
<p><a href="http://lh5.ggpht.com/_-C4uSahz1Gg/S31vxEDbZqI/AAAAAAAABcg/y5viS3JM5as/s1600-h/image%5B7%5D.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" src="http://lh4.ggpht.com/_-C4uSahz1Gg/S31vxlxQ7BI/AAAAAAAABck/RMH3Br1F6lg/image_thumb%5B7%5D.png?imgmax=800" border="0" alt="image" width="295" height="172" /></a></p>
<p>As for the DECIMAL column, the outcome is as expected. But look at the totals for the FLOAT column. It's perfectly understandable, the sum will reveal some rounding errors. What really puzzled me is the difference between the numbers. Why isn't the rounding error the same for all executions?</p>
<p>I was pretty sure that I discovered a bug in SQL Server and posted a regarding item on MSFT's connect platform (see <a href="https://connect.microsoft.com/SQLServer/feedback/details/465147/select-sum-is-non-deterministic-when-adding-the-column-values-of-datatype-float" target="_blank">here</a>).</p>
<p>Unfortunately nobody cared about my problem, and so I took the opportunity of talking to some fellows of the SQL Server CAT team on the occasion of the 2009 PASS Summit. After a while, I received an explanation which I'd like to repeat here.</p>
<p>The query is executed in parallel, as the plan reveals:</p>
<p><a href="http://lh3.ggpht.com/_-C4uSahz1Gg/S31vyk37WKI/AAAAAAAABco/F0U8x6VjF-w/s1600-h/image1%5B1%5D.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" src="http://lh4.ggpht.com/_-C4uSahz1Gg/S31vz8UvHoI/AAAAAAAABcs/IBL6nCIgdGU/image1_thumb.png?imgmax=800" border="0" alt="image" width="982" height="87" /></a></p>
<p>When summing up values, usually the summation sequence doesn't matter. (If you remember some mathematics from school that's what the commutative law of addition is about). Therefore, reading values in multiple threads and adding up the values in any arbitrary order is perfect, as the order doesn't have any influence on the result. Well, at least theoretically. When adding float values, there's floating point arithmetic rounding errors with every addition. These added-up rounding errors are the reason for the non-zero values of the float totals in our example. So that's ok, but why different results with almost every execution? The reason for this is parallel execution. Added-up rounding errors <em>depend</em> on the sequence, so the commutative law does not really apply to these errors. There's a chance that the sequence of rows changes with every execution, if the query is executed in parallel. And that's why the results change, dependent only on some butterfly wing movements at the other side of the world.</p>
<p>If we add the MAXDOP 1 query hint, only one thread is utilized and the results are the same for every execution, although rounding errors still remain present. So this query:</p>
<table class="MsoTableGrid" style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8eb4e3; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8eb4e3; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes">
<td style="border: 1pt dashed #8eb4e3; padding: 0in 5.4pt; width: 678.75pt;" width="905" valign="top">
<p class="MsoNormal" style="line-height: normal; margin: 6pt 0in; mso-layout-grid-align: none"><span style="font-family: &quot;Lucida Console&quot;; color: blue; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes; mso-ansi-language: en-us" lang="EN-US">select</span><span style="font-family: &quot;Lucida Console&quot;; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes; mso-ansi-language: en-us" lang="EN-US"> <span style="color: fuchsia">sum</span><span style="color: gray">(</span>floatVal<span style="color: gray">)</span> <span style="color: blue">as</span> SumFloatVal               <br /><span style="mso-spacerun: yes"> </span><span style="color: gray">,</span><span style="color: fuchsia">sum</span><span style="color: gray">(</span>decimalVal<span style="color: gray">)</span> <span style="color: blue">as</span> SumDecimalVal               <br /><span style="mso-spacerun: yes"> </span><span style="color: blue">from</span> SumTest <span style="color: blue">option </span><span style="color: gray">(</span><span style="color: blue">maxdop</span> 1<span style="color: gray">)</span> </span></p>
</td>
</tr>
</tbody>
</table>
<p>will be executed by using the following (single thread) execution plan:</p>
<p><a href="http://lh6.ggpht.com/_-C4uSahz1Gg/S31v040xHTI/AAAAAAAABcw/S3sP1BqTx8c/s1600-h/image7%5B1%5D.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" src="http://lh3.ggpht.com/_-C4uSahz1Gg/S31v3V9wRDI/AAAAAAAABc4/nu24EdZdhyE/image7_thumb.png?imgmax=800" border="0" alt="image" width="511" height="85" /></a></p>
<p>This time the result (and also the rounding error) is always the same.</p>
<p>Pretty soon after delivering the explanation, the bug was closed. Reason: the observed behavior is "by design".</p>
<p>I can understand that the problem originates from computer resp. processor architecture and MSFT has no chance of control therefore.</p>
<p>Although.</p>
<p>When using SSAS' write back functionality, SSAS will always create numeric columns of FLOAT data types. There's no chance of manipulating the data type; it's <em>always</em> float!</p>
<p>Additionally, SSAS more often than not inserts rows into write back tables with vastly large resp. small values. When looking an these rows, it appeared that they are created solely with the intention of summing up to zero. We discovered plenty of these rows containing inverse values that usually should nullify in total, but apparently don't. By the way that's why closing the bug with the "By Design" explanation makes me somewhat sad.</p>
<p>So, probably avoiding FLOATs is a good idea! Unfortunately, this is simply not possible in all cases and sometimes out of our control.</p>]]></content:encoded>
								<comments>https://www.insidesql.org/blogs/holgerschmeling/2010/11/02/did-you-know-aggregate-functions-on-floats-may-be-non-deterministic#comments</comments>
			<wfw:commentRss>https://www.insidesql.org/blogs/holgerschmeling/?tempskin=_rss2&#38;disp=comments&#38;p=1718</wfw:commentRss>
		</item>
				<item>
			<title>No automatically created or updated statistics for read-only databases</title>
			<link>https://www.insidesql.org/blogs/holgerschmeling/2010/11/01/no-automatically-created-or-updated-statistics-for-read-only-databases</link>
			<pubDate>Mon, 01 Nov 2010 13:37:42 +0000</pubDate>			<dc:creator>Holger Schmeling</dc:creator>
			<category domain="main">SQL Server Performance</category>			<guid isPermaLink="false">1711@https://www.insidesql.org/blogs/</guid>
						<description>&lt;p&gt;Ok, that&#039;s not really the latest news and also well documented. But keep in mind that &lt;em&gt;database snapshots&lt;/em&gt; also fall into the category of read-only databases, so you won&#039;t see automatically maintained statistics for these as well.&lt;/p&gt;
&lt;p&gt;I&#039;ve seen the advice of taking a snapshot from a mirrored database for reporting purposes many times. Even books online contains a chapter &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/ms175511.aspx&quot; target=&quot;_blank&quot;&gt;Database Mirroring and Database Snapshots&lt;/a&gt;, where the scenario is explained.&lt;/p&gt;
&lt;p&gt;The intention is to decouple your resource intensive reporting queries from the OLTP system which is generally a good idea. But keep in mind that:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Reporting queries are highly unpredictable, and &lt;/li&gt;
&lt;li&gt;Reporting queries differ from OLTP queries. &lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;So there&#039;s more than only a slightly a chance that query performance will suffer from missing statistics in your reporting snapshot, since the underlying OLTP database simply does not contain all statistics (or indexes) that your reporting applications could take advantage of. These missing statistics can&#039;t be added in the snapshot, because it&#039;s a read-only database. Additionally, you won&#039;t experience any automatic updates of stale statistics in the snapshot. And moreover, any added or updated statistics in the source database are not transferred into the snapshot, of course. This can affect your query performance significantly!&lt;/p&gt;
&lt;p&gt;Have a look at the following example:&lt;/p&gt;
&lt;table class=&quot;MsoTableGrid&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8eb4e3; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8eb4e3; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102&quot; border=&quot;1&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;&gt;
&lt;tbody&gt;
&lt;tr style=&quot;mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes&quot;&gt;
&lt;td style=&quot;border: 1pt dashed #8eb4e3; padding: 0in 5.4pt; width: 678.75pt;&quot; width=&quot;905&quot; valign=&quot;top&quot;&gt;
&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin: 6pt 0in; mso-layout-grid-align: none&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Lucida Console&amp;quot;; color: blue; font-size: 12pt; mso-bidi-font-family: &#039;Times New Roman&#039;; mso-no-proof: yes; mso-ansi-language: en-us&quot; lang=&quot;EN-US&quot;&gt;use&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Lucida Console&amp;quot;; font-size: 12pt; mso-bidi-font-family: &#039;Times New Roman&#039;; mso-no-proof: yes; mso-ansi-language: en-us&quot; lang=&quot;EN-US&quot;&gt; &lt;span style=&quot;color: blue&quot;&gt;master                &lt;br /&gt;go                 &lt;br /&gt; &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: green&quot;&gt;-- Create test database                &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: blue&quot;&gt;create&lt;/span&gt; &lt;span style=&quot;color: blue&quot;&gt;database&lt;/span&gt; ssBase               &lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;go                &lt;br /&gt;use&lt;/span&gt; ssBase               &lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;go                &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: green&quot;&gt;-- create test table and insert 10000 rows                &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: blue&quot;&gt;create&lt;/span&gt; &lt;span style=&quot;color: blue&quot;&gt;table&lt;/span&gt; t1               &lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: gray&quot;&gt;(                &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;c1 &lt;span style=&quot;color: blue&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: gray&quot;&gt;not&lt;/span&gt; &lt;span style=&quot;color: gray&quot;&gt;null&lt;/span&gt; &lt;span style=&quot;color: blue&quot;&gt;primary&lt;/span&gt; &lt;span style=&quot;color: blue&quot;&gt;key                &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: gray&quot;&gt;,&lt;/span&gt;c2 &lt;span style=&quot;color: blue&quot;&gt;int&lt;/span&gt; &lt;span style=&quot;color: gray&quot;&gt;not&lt;/span&gt; &lt;span style=&quot;color: gray&quot;&gt;null                &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: gray&quot;&gt;)                &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: blue&quot;&gt;go                &lt;br /&gt;go                 &lt;br /&gt;insert&lt;/span&gt; t1&lt;span style=&quot;color: gray&quot;&gt;(&lt;/span&gt;c1&lt;span style=&quot;color: gray&quot;&gt;,&lt;/span&gt;c2&lt;span style=&quot;color: gray&quot;&gt;)                &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: blue&quot;&gt;select&lt;/span&gt; &lt;span style=&quot;color: blue&quot;&gt;top&lt;/span&gt; 10000               &lt;br /&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: fuchsia&quot;&gt;row_number&lt;/span&gt;&lt;span style=&quot;color: gray&quot;&gt;()&lt;/span&gt; &lt;span style=&quot;color: blue&quot;&gt;over&lt;/span&gt;&lt;span style=&quot;color: gray&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: blue&quot;&gt;order&lt;/span&gt; &lt;span style=&quot;color: blue&quot;&gt;by&lt;/span&gt; &lt;span style=&quot;color: fuchsia&quot;&gt;current_timestamp&lt;/span&gt;&lt;span style=&quot;color: gray&quot;&gt;)                &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: gray&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: fuchsia&quot;&gt;checksum&lt;/span&gt;&lt;span style=&quot;color: gray&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: fuchsia&quot;&gt;newid&lt;/span&gt;&lt;span style=&quot;color: gray&quot;&gt;())                &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: blue&quot;&gt;from&lt;/span&gt; &lt;span style=&quot;color: green&quot;&gt;sys&lt;/span&gt;&lt;span style=&quot;color: gray&quot;&gt;.&lt;/span&gt;fulltext_system_stopwords               &lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt;go&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt; &lt;br /&gt; &lt;br /&gt;&lt;span style=&quot;color: green&quot;&gt;-- create snapshot of test database                &lt;br /&gt;-- NOTE: the filename has to be adjusted                 &lt;br /&gt;-- for your own experimenting                 &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: blue&quot;&gt;create&lt;/span&gt; &lt;span style=&quot;color: blue&quot;&gt;database&lt;/span&gt; ssBase_SS &lt;span style=&quot;color: blue&quot;&gt;on                &lt;br /&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: gray&quot;&gt;(                &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;name &lt;span style=&quot;color: gray&quot;&gt;=&lt;/span&gt; ssBase&lt;br /&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: gray&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: blue&quot;&gt;filename&lt;/span&gt; &lt;span style=&quot;color: gray&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: red&quot;&gt;&#039;e:\SqlTestData\ssBase_SS.ss&#039;                &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Lucida Console&amp;quot;; color: gray; font-size: 12pt; mso-bidi-font-family: &#039;Times New Roman&#039;; mso-no-proof: yes&quot;&gt;)              &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Lucida Console&amp;quot;; font-size: 12pt; mso-bidi-font-family: &#039;Times New Roman&#039;; mso-no-proof: yes&quot;&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: blue&quot;&gt;as&lt;/span&gt; &lt;span style=&quot;color: blue&quot;&gt;snapshot&lt;/span&gt; &lt;span style=&quot;color: blue&quot;&gt;of&lt;/span&gt; ssBase&lt;span style=&quot;color: gray&quot;&gt;;                &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: blue&quot;&gt;go&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Lucida Console&amp;quot;; font-size: 12pt; mso-bidi-font-family: &#039;Times New Roman&#039;; mso-no-proof: yes; mso-ansi-language: en-us&quot; lang=&quot;EN-US&quot;&gt; &lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;The script above creates a test database with one table and adds some rows to the table before creating a snapshot of this database. As we have never used column c2 in any query (besides the INSERT), there won&#039;t be any statistics for column t1.c2.&lt;/p&gt;
&lt;p&gt;Now let&#039;s query the snapshot and have a look at the actual execution plan. Here&#039;s the query:&lt;/p&gt;
&lt;table class=&quot;MsoTableGrid&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8eb4e3; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8eb4e3; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102&quot; border=&quot;1&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;&gt;
&lt;tbody&gt;
&lt;tr style=&quot;mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes&quot;&gt;
&lt;td style=&quot;border: 1pt dashed #8eb4e3; padding: 0in 5.4pt; width: 678.75pt;&quot; width=&quot;905&quot; valign=&quot;top&quot;&gt;
&lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin: 6pt 0in; mso-layout-grid-align: none&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Lucida Console&amp;quot;; color: green; font-size: 12pt; mso-bidi-font-family: &#039;Times New Roman&#039;; mso-no-proof: yes; mso-ansi-language: en-us&quot; lang=&quot;EN-US&quot;&gt;-- Be sure to show the actual execution plan              &lt;br /&gt;-- for the following query               &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Lucida Console&amp;quot;; color: blue; font-size: 12pt; mso-bidi-font-family: &#039;Times New Roman&#039;; mso-no-proof: yes; mso-ansi-language: en-us&quot; lang=&quot;EN-US&quot;&gt;use&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Lucida Console&amp;quot;; font-size: 12pt; mso-bidi-font-family: &#039;Times New Roman&#039;; mso-no-proof: yes; mso-ansi-language: en-us&quot; lang=&quot;EN-US&quot;&gt; ssBase_SS              &lt;br /&gt;&lt;span style=&quot;color: blue&quot;&gt; &lt;br /&gt;select&lt;/span&gt; &lt;span style=&quot;color: gray&quot;&gt;*&lt;/span&gt; &lt;span style=&quot;color: blue&quot;&gt;from&lt;/span&gt; t1               &lt;br /&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: blue&quot;&gt;where&lt;/span&gt; c2 &lt;span style=&quot;color: gray&quot;&gt;=&lt;/span&gt; 10 &lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Here&#039;s the actual execution plan:&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;/blogs/media/blogs/holgerschmeling/windows-live-writer/noautomaticallycreatedorupdatedstatistic_e435/image_2.png&quot;&gt;&lt;img style=&quot;border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px&quot; title=&quot;image&quot; src=&quot;/blogs/media/blogs/holgerschmeling/windows-live-writer/noautomaticallycreatedorupdatedstatistic_e435/image_thumb.png&quot; border=&quot;0&quot; alt=&quot;image&quot; width=&quot;630&quot; height=&quot;500&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Clearly evident that the optimizer detects a missing statistics, although the options AUTO CREATE STATISTICS and AUTO UPDATE STATISTICS have both been set to ON. The plan reveals a noticeable difference between the actual and estimated number of rows and also a warning regarding the missing statistics.&lt;/p&gt;
&lt;p&gt;So, keep that in mind when using snapshots for reporting applications.&lt;/p&gt;
&lt;p&gt;If you&#039;d like to find out more about SQL Server statistics, you may want to check out my series of two articles, published recently on the &lt;a href=&quot;http://www.simple-talk.com&quot; target=&quot;_blank&quot;&gt;Simple-Talk&lt;/a&gt; platform.&lt;/p&gt;
&lt;p&gt;Part 1: &lt;a href=&quot;http://www.simple-talk.com/sql/performance/queries,-damned-queries-and-statistics/&quot; target=&quot;_blank&quot;&gt;Queries, Damned Queries and Statistics&lt;/a&gt; &lt;br /&gt;Part 2: &lt;a href=&quot;http://www.simple-talk.com/sql/performance/sql-server-statistics-problems-and-solutions/&quot; target=&quot;_blank&quot;&gt;SQL Server Statistics: Problems and Solutions&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;It&#039;s free, so you might want to give it a try. Feel free to vote, if you like it!&lt;/p&gt;</description>
			<content:encoded><![CDATA[<p>Ok, that's not really the latest news and also well documented. But keep in mind that <em>database snapshots</em> also fall into the category of read-only databases, so you won't see automatically maintained statistics for these as well.</p>
<p>I've seen the advice of taking a snapshot from a mirrored database for reporting purposes many times. Even books online contains a chapter <a href="http://msdn.microsoft.com/en-us/library/ms175511.aspx" target="_blank">Database Mirroring and Database Snapshots</a>, where the scenario is explained.</p>
<p>The intention is to decouple your resource intensive reporting queries from the OLTP system which is generally a good idea. But keep in mind that:</p>
<ol>
<li>Reporting queries are highly unpredictable, and </li>
<li>Reporting queries differ from OLTP queries. </li>
</ol>
<p>So there's more than only a slightly a chance that query performance will suffer from missing statistics in your reporting snapshot, since the underlying OLTP database simply does not contain all statistics (or indexes) that your reporting applications could take advantage of. These missing statistics can't be added in the snapshot, because it's a read-only database. Additionally, you won't experience any automatic updates of stale statistics in the snapshot. And moreover, any added or updated statistics in the source database are not transferred into the snapshot, of course. This can affect your query performance significantly!</p>
<p>Have a look at the following example:</p>
<table class="MsoTableGrid" style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8eb4e3; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8eb4e3; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes">
<td style="border: 1pt dashed #8eb4e3; padding: 0in 5.4pt; width: 678.75pt;" width="905" valign="top">
<p class="MsoNormal" style="line-height: normal; margin: 6pt 0in; mso-layout-grid-align: none"><span style="font-family: &quot;Lucida Console&quot;; color: blue; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes; mso-ansi-language: en-us" lang="EN-US">use</span><span style="font-family: &quot;Lucida Console&quot;; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes; mso-ansi-language: en-us" lang="EN-US"> <span style="color: blue">master                <br />go                 <br /> <br /></span><span style="color: green">-- Create test database                <br /></span><span style="color: blue">create</span> <span style="color: blue">database</span> ssBase               <br /><span style="color: blue">go                <br />use</span> ssBase               <br /><span style="color: blue">go                <br /></span><span style="color: green">-- create test table and insert 10000 rows                <br /></span><span style="color: blue">create</span> <span style="color: blue">table</span> t1               <br /><span style="color: blue"><span style="mso-spacerun: yes"> </span></span><span style="color: gray">(                <br /></span><span style="mso-spacerun: yes"> </span>c1 <span style="color: blue">int</span> <span style="color: gray">not</span> <span style="color: gray">null</span> <span style="color: blue">primary</span> <span style="color: blue">key                <br /></span><span style="mso-spacerun: yes"> </span><span style="color: gray">,</span>c2 <span style="color: blue">int</span> <span style="color: gray">not</span> <span style="color: gray">null                <br /></span><span style="mso-spacerun: yes"> </span><span style="color: gray">)                <br /></span><span style="color: blue">go                <br />go                 <br />insert</span> t1<span style="color: gray">(</span>c1<span style="color: gray">,</span>c2<span style="color: gray">)                <br /></span><span style="mso-spacerun: yes"> </span><span style="color: blue">select</span> <span style="color: blue">top</span> 10000               <br /><span style="mso-spacerun: yes"> </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> <span style="color: fuchsia">current_timestamp</span><span style="color: gray">)                <br /></span><span style="mso-spacerun: yes"> </span><span style="color: gray">,</span><span style="color: fuchsia">checksum</span><span style="color: gray">(</span><span style="color: fuchsia">newid</span><span style="color: gray">())                <br /></span><span style="mso-spacerun: yes"> </span><span style="color: blue">from</span> <span style="color: green">sys</span><span style="color: gray">.</span>fulltext_system_stopwords               <br /><span style="color: blue">go</span><span style="mso-spacerun: yes"> </span> <br /> <br /><span style="color: green">-- create snapshot of test database                <br />-- NOTE: the filename has to be adjusted                 <br />-- for your own experimenting                 <br /></span><span style="color: blue">create</span> <span style="color: blue">database</span> ssBase_SS <span style="color: blue">on                <br /><span style="mso-spacerun: yes"> </span></span><span style="color: gray">(                <br /></span><span style="mso-spacerun: yes"> </span>name <span style="color: gray">=</span> ssBase<br /><span style="mso-spacerun: yes"> </span><span style="color: gray">,</span><span style="color: blue">filename</span> <span style="color: gray">=</span> <span style="color: red">'e:\SqlTestData\ssBase_SS.ss'                <br /></span><span style="mso-spacerun: yes"> </span></span><span style="font-family: &quot;Lucida Console&quot;; color: gray; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes">)              <br /></span><span style="font-family: &quot;Lucida Console&quot;; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes"><span style="mso-spacerun: yes"> </span><span style="color: blue">as</span> <span style="color: blue">snapshot</span> <span style="color: blue">of</span> ssBase<span style="color: gray">;                <br /></span><span style="color: blue">go</span></span><span style="font-family: &quot;Lucida Console&quot;; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes; mso-ansi-language: en-us" lang="EN-US"> </span></p>
</td>
</tr>
</tbody>
</table>
<p>The script above creates a test database with one table and adds some rows to the table before creating a snapshot of this database. As we have never used column c2 in any query (besides the INSERT), there won't be any statistics for column t1.c2.</p>
<p>Now let's query the snapshot and have a look at the actual execution plan. Here's the query:</p>
<table class="MsoTableGrid" style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; background: #f5f0df; border-top: medium none; border-right: medium none; mso-border-alt: dashed #8eb4e3 .5pt; mso-border-themecolor: text2; mso-border-themetint: 102; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt dashed #8eb4e3; mso-border-insideh-themecolor: text2; mso-border-insideh-themetint: 102; mso-border-insidev: .5pt dashed #8eb4e3; mso-border-insidev-themecolor: text2; mso-border-insidev-themetint: 102" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes">
<td style="border: 1pt dashed #8eb4e3; padding: 0in 5.4pt; width: 678.75pt;" width="905" valign="top">
<p class="MsoNormal" style="line-height: normal; margin: 6pt 0in; mso-layout-grid-align: none"><span style="font-family: &quot;Lucida Console&quot;; color: green; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes; mso-ansi-language: en-us" lang="EN-US">-- Be sure to show the actual execution plan              <br />-- for the following query               <br /></span><span style="font-family: &quot;Lucida Console&quot;; color: blue; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes; mso-ansi-language: en-us" lang="EN-US">use</span><span style="font-family: &quot;Lucida Console&quot;; font-size: 12pt; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes; mso-ansi-language: en-us" lang="EN-US"> ssBase_SS              <br /><span style="color: blue"> <br />select</span> <span style="color: gray">*</span> <span style="color: blue">from</span> t1               <br /><span style="mso-spacerun: yes"> </span><span style="color: blue">where</span> c2 <span style="color: gray">=</span> 10 </span></p>
</td>
</tr>
</tbody>
</table>
<p>Here's the actual execution plan:</p>
<p><a href="/blogs/media/blogs/holgerschmeling/windows-live-writer/noautomaticallycreatedorupdatedstatistic_e435/image_2.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" src="/blogs/media/blogs/holgerschmeling/windows-live-writer/noautomaticallycreatedorupdatedstatistic_e435/image_thumb.png" border="0" alt="image" width="630" height="500" /></a></p>
<p>Clearly evident that the optimizer detects a missing statistics, although the options AUTO CREATE STATISTICS and AUTO UPDATE STATISTICS have both been set to ON. The plan reveals a noticeable difference between the actual and estimated number of rows and also a warning regarding the missing statistics.</p>
<p>So, keep that in mind when using snapshots for reporting applications.</p>
<p>If you'd like to find out more about SQL Server statistics, you may want to check out my series of two articles, published recently on the <a href="http://www.simple-talk.com" target="_blank">Simple-Talk</a> platform.</p>
<p>Part 1: <a href="http://www.simple-talk.com/sql/performance/queries,-damned-queries-and-statistics/" target="_blank">Queries, Damned Queries and Statistics</a> <br />Part 2: <a href="http://www.simple-talk.com/sql/performance/sql-server-statistics-problems-and-solutions/" target="_blank">SQL Server Statistics: Problems and Solutions</a></p>
<p>It's free, so you might want to give it a try. Feel free to vote, if you like it!</p>]]></content:encoded>
								<comments>https://www.insidesql.org/blogs/holgerschmeling/2010/11/01/no-automatically-created-or-updated-statistics-for-read-only-databases#comments</comments>
			<wfw:commentRss>https://www.insidesql.org/blogs/holgerschmeling/?tempskin=_rss2&#38;disp=comments&#38;p=1711</wfw:commentRss>
		</item>
			</channel>
</rss>
