<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://sqlblog.com/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"><title type="html">Tibor Karaszi</title><subtitle type="html" /><id>http://sqlblog.com/blogs/tibor_karaszi/atom.aspx</id><link rel="alternate" type="text/html" href="http://sqlblog.com/blogs/tibor_karaszi/default.aspx" /><link rel="self" type="application/atom+xml" href="http://sqlblog.com/blogs/tibor_karaszi/atom.aspx" /><generator uri="http://communityserver.org" version="2.1.61129.1">Community Server</generator><updated>2008-07-07T15:17:00Z</updated><entry><title>Rebuild master in SQL Server 2008</title><link rel="alternate" type="text/html" href="http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/29/rebuild-master-in-sql-server-2008.aspx" /><id>http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/29/rebuild-master-in-sql-server-2008.aspx</id><published>2008-08-29T18:18:00Z</published><updated>2008-08-29T18:18:00Z</updated><content type="html">&lt;P&gt;You might have read an earlier blog entry about my problems to remove a Data Collector (DC) information in SQL Server 2008. I still haven't found any info on how to do this, but my questions in the MVP group triggered some activity.&lt;/P&gt;
&lt;P&gt;Bob Ward looked into how to rebuild the system databases. This was on my list to try (after removing DC config and if that didn't work rebuilding msdb). But Books Online had very little information on how to actually do the rebuild. Since there were quite many changes in setup between 2005 and 2008, I didn't feel like trial and error based on how we did this in 2005. &lt;/P&gt;
&lt;P&gt;Bob helped me out with some information on how to do the rebuild and it is very easy! I now have a bat file which does rebuild of three instances - and it only takes 5 minutes. And even better: no installation media is required - and it also remembers the collation for my system databases!&lt;/P&gt;
&lt;P&gt;Enough said. Check out Bob's blog post at: &lt;A href="http://blogs.msdn.com/psssql/archive/2008/08/29/how-to-rebuild-system-databases-in-sql-server-2008.aspx"&gt;http://blogs.msdn.com/psssql/archive/2008/08/29/how-to-rebuild-system-databases-in-sql-server-2008.aspx&lt;/A&gt;&lt;/P&gt;
&lt;BR&gt;&lt;div class = "shareblock"&gt;&lt;span class = "shareblockTitle"&gt;Share this post:&lt;/span&gt;&lt;span class = "shareblockLink"&gt; &lt;a href = "mailto:?subject=Rebuild master in SQL Server 2008&amp;amp;body=Seen on SQLblog.com: %0A%0A%09Rebuild master in SQL Server 2008%0A%0Ahttp://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/29/rebuild-master-in-sql-server-2008.aspx" target="_blank" title = "Email Rebuild master in SQL Server 2008"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/29/rebuild-master-in-sql-server-2008.aspx&amp;amp;title=Rebuild+master+in+SQL+Server+2008" target="_blank" title = "Submit Rebuild master in SQL Server 2008 to del.icio.us"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/29/rebuild-master-in-sql-server-2008.aspx&amp;amp;phase=2" target="_blank" title = "Submit Rebuild master in SQL Server 2008 to digg.com"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/29/rebuild-master-in-sql-server-2008.aspx&amp;amp;title=Rebuild+master+in+SQL+Server+2008" target="_blank" title = "Submit Rebuild master in SQL Server 2008 to reddit.com"&gt;reddit!&lt;/a&gt; |  &lt;a href = "http://www.dotnetkicks.com/submit/?url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/29/rebuild-master-in-sql-server-2008.aspx&amp;amp;title=Rebuild+master+in+SQL+Server+2008" target="_blank" title = "Submit Rebuild master in SQL Server 2008 to DotNetKicks"&gt;kick it!&lt;/a&gt; |  &lt;a href = "https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;mkt=en-us&amp;amp;url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/29/rebuild-master-in-sql-server-2008.aspx&amp;amp;title=Rebuild+master+in+SQL+Server+2008&amp;amp;;top=1" target="_blank" title = "Add Rebuild master in SQL Server 2008 to Live Bookmarks"&gt;live it!&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;img src="http://info.sqlblog.com/a.aspx?ZoneID=0&amp;BannerID=12&amp;AdvertiserID=1&amp;CampaignID=12&amp;Task=Get&amp;Mode=TEXT&amp;SiteID=1&amp;RandomNumber=463323" width="1" height="1" border="0"&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=8655" width="1" height="1"&gt;</content><author><name>TiborKaraszi</name><uri>http://sqlblog.com/members/TiborKaraszi.aspx</uri></author><category term="Tools" scheme="http://sqlblog.com/blogs/tibor_karaszi/archive/tags/Tools/default.aspx" /><category term="Backup" scheme="http://sqlblog.com/blogs/tibor_karaszi/archive/tags/Backup/default.aspx" /><category term="Installation" scheme="http://sqlblog.com/blogs/tibor_karaszi/archive/tags/Installation/default.aspx" /></entry><entry><title>Execution plan re-use, sp_executesql and TSQL variables</title><link rel="alternate" type="text/html" href="http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/29/execution-plan-re-use-sp-executesql-and-tsql-variables.aspx" /><id>http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/29/execution-plan-re-use-sp-executesql-and-tsql-variables.aspx</id><published>2008-08-29T06:34:00Z</published><updated>2008-08-29T06:34:00Z</updated><content type="html">&lt;P&gt;Let me start by saying that the contents of this post is not very advanced. If you have read the excellent paper "Batch Compilation, Recompilation, and Plan Caching Issues in SQL Server 2005", &lt;A href="http://www.microsoft.com/technet/prodtechnol/sql/2005/recomp.mspx"&gt;http://www.microsoft.com/technet/prodtechnol/sql/2005/recomp.mspx&lt;/A&gt;&amp;nbsp;and understood it, you would already know below, and much more...&lt;/P&gt;
&lt;P&gt;I was reading a thread in the open newsgroups today (.tools, posted by Mike), about an advice that the SQL Server 2005 Database Engine Tuning Advisor&amp;nbsp;apparently gave. It advices to replace sp_executesql usage with declaring TSQL variables and using those in the WHERE clause. Translated to the Adventureworks database, it advices that instead of 1) below, we should use&amp;nbsp;2) below.&lt;/P&gt;
&lt;P&gt;&lt;CODE style="FONT-SIZE:12px;"&gt;&lt;SPAN style="COLOR:blue;"&gt;&lt;FONT face=Arial color=#000000 size=2&gt;1)&lt;BR&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;CODE style="FONT-SIZE:12px;"&gt;&lt;SPAN style="COLOR:#434343;"&gt;&lt;FONT color=#0000ff&gt;EXEC&amp;nbsp;&lt;/FONT&gt;&lt;SPAN style="COLOR:darkred;"&gt;sp_executesql&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:red;"&gt;N'SELECT&amp;nbsp;FirstName,&amp;nbsp;LastName,&amp;nbsp;PersonType,&amp;nbsp;Title &lt;BR&gt;FROM&amp;nbsp;Person.Person &lt;BR&gt;WHERE&amp;nbsp;LastName&amp;nbsp;=&amp;nbsp;@P1'&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;, &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:red;"&gt;N'@P1&amp;nbsp;nvarchar(50)'&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:red;"&gt;'Diaz'&lt;/SPAN&gt;&lt;FONT color=#000000&gt; &lt;BR&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;CODE style="FONT-SIZE:12px;"&gt;&lt;SPAN style="COLOR:#434343;"&gt;&lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;&lt;SPAN style="COLOR:blue;"&gt;&lt;FONT face=Arial color=#000000 size=2&gt;2)&lt;BR&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;DECLARE&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:#434343;"&gt;@P1&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;NVARCHAR&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;50&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;) &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;SET&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:#434343;"&gt;@P1&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;=&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:red;"&gt;'Diaz' &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;SELECT&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;FirstName&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;LastName&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;PersonType&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;Title &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;FROM&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;Person.Person &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;WHERE&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;LastName&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;=&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:#434343;"&gt;@P1 &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;Now, I could not reproduce this (make DTA give me the same advice, to replace 1) with 2) ). Perhaps I misunderstood the poster in the group, it is because I'm running SQL Server 2008 DTA and engine, I'm not looking in the right place for that advice, my data isn't representative, I'm running the DTA with some other settings, etc..&amp;nbsp;But say that DTA does indeed give such an advice, would would it do that? To be honest, I don't know. It can hardly have enough information to determine whether 1) or 2) is the best choice.&lt;/P&gt;
&lt;P&gt;In short: Say we have an index on the LastName column and the name we look for can either be a very common name, like perhaps "Smith", or a not so common name, like "Karaszi". For the more common name, a table scan might be the best choice, where for the not-so-common name, an index seek it probably best thing. OK, a very simple example, but serves well for this discussion.&lt;/P&gt;
&lt;P&gt;Back to the difference between 1) and 2). There are potentially very important differences between the two:&lt;/P&gt;
&lt;P&gt;For 1), SQL Server will determine a plan based on the contents of the parameter when the plan is created. I.e., it can determine selectivity based on that and determine whether it is a good idea to use an index or not. The plan is then cached and can be re-used. But what if we for the first execution pass in something which is very selective, but typically we are &lt;STRONG&gt;not&lt;/STRONG&gt; very selective? Or the other way around? I,e, the plan for one case might not be optimal for some other case. This is where we have new optimizer hints in 2005 like OPTIMIZE FOR and the RECOMPILE hints. I will not go into details about these here, since I'm focusing on the differences between 1) and 2). See the white paper I mentioned, and of course Books Online, for more details.&lt;/P&gt;
&lt;P&gt;For 2), SQL Server (or rather: the optimizer) has no knowledge of the contents of the variable when the plan is produced. So it cannot use the statistics to determine selectivity. In above case, it instead uses density (stored with the statistics, assuming such exists for the column). Density is basically the 1/ number of unique values for the column(s). This might be a good representation for a typical lastname, but perhaps not too good for a very common or a very uncommon lastname. Now, in 2005, we have hints for these situations as well (RECOMPILE), but again, that is not the point here.&lt;/P&gt;
&lt;P&gt;In order for DTA to give the best advice here, it would have to know about the distribution over the data for that column and also have many executions of that query to see if "all" executions are using a typical value (sp_executesql might be better) or if the stored density value is a good representation for "all" queries that are passed from the clients. I very much doubt that DTA has this level of sophistication. Basically, I don't know why it advices this. There might be other aspects, like "avoid dynamic SQL" (which whether that holds for this case we could argue in another post), but DTA is about performance, not best practices. &lt;/P&gt;
&lt;P&gt;Bottom line is that these things are not simple and we should be very cautious with "rules of thumbs".&lt;/P&gt;
&lt;P&gt;Here's some TSQL code to demonstrate the differences between 1) and 2). As always, only execute after you read and understood the code!&lt;/P&gt;&lt;CODE style="FONT-SIZE:12px;"&gt;&lt;SPAN style="COLOR:green;"&gt;--Create&amp;nbsp;a&amp;nbsp;copy&amp;nbsp;of&amp;nbsp;the&amp;nbsp;person&amp;nbsp;table &lt;BR&gt;--We&amp;nbsp;will&amp;nbsp;have&amp;nbsp;lots&amp;nbsp;of&amp;nbsp;"Diaz"&amp;nbsp;and&amp;nbsp;very&amp;nbsp;few&amp;nbsp;"Gimmi" &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;IF&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:magenta;"&gt;OBJECT_ID&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="COLOR:red;"&gt;'p'&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;)&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;IS&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;NOT&amp;nbsp;NULL&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;DROP&amp;nbsp;TABLE&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;p &lt;BR&gt;GO &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;SELECT&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;*&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;INTO&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;p&amp;nbsp; &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;FROM&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;Person.Person &lt;BR&gt;&lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;CREATE&amp;nbsp;INDEX&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;x&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;ON&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;dbo.p&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;LastName&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;) &lt;BR&gt;&lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:green;"&gt;--Create&amp;nbsp;lots&amp;nbsp;of&amp;nbsp;Diaz &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;INSERT&amp;nbsp;INTO&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;p &lt;BR&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;SELECT&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;BusinessEntityID&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;+&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;30000&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;PersonType&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;NameStyle&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;Title&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;FirstName&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;MiddleName&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:red;"&gt;N'Diaz'&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;Suffix&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;EmailPromotion&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;AdditionalContactInfo&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;Demographics&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;rowguid&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;ModifiedDate &lt;BR&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;FROM&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;p &lt;BR&gt;&amp;nbsp; &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:green;"&gt;--Make&amp;nbsp;sure&amp;nbsp;we&amp;nbsp;have&amp;nbsp;up-to-date&amp;nbsp;statistics &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;UPDATE&amp;nbsp;STATISTICS&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;p&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;WITH&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;FULLSCAN &lt;BR&gt;&lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:green;"&gt;--Verify&amp;nbsp;execution&amp;nbsp;plan&amp;nbsp;and&amp;nbsp;I/O&amp;nbsp;cost &lt;BR&gt;--for&amp;nbsp;table&amp;nbsp;scan&amp;nbsp;with&amp;nbsp;low&amp;nbsp;selectivity&amp;nbsp; &lt;BR&gt;--and&amp;nbsp;index&amp;nbsp;seek&amp;nbsp;with&amp;nbsp;high&amp;nbsp;selectivity &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;SET&amp;nbsp;STATISTICS&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;IO&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;ON &lt;BR&gt;&lt;BR&gt;DBCC&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;FREEPROCCACHE &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;SELECT&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;*&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;FROM&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;p&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;WHERE&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;LastName&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;=&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:red;"&gt;'Diaz' &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:green;"&gt;--20183&amp;nbsp;rows,&amp;nbsp;table&amp;nbsp;scan,&amp;nbsp;7612&amp;nbsp;pages &lt;BR&gt;&lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;DBCC&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;FREEPROCCACHE &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;SELECT&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;*&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;FROM&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;p&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;WHERE&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;LastName&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;=&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:red;"&gt;'Gimmi' &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:green;"&gt;--1&amp;nbsp;row,&amp;nbsp;index&amp;nbsp;seek,&amp;nbsp;3&amp;nbsp;pages &lt;BR&gt;&lt;BR&gt;&lt;BR&gt;&lt;BR&gt;------------------------------------------------------------ &lt;BR&gt;--sp_execute&amp;nbsp;alternative &lt;BR&gt;------------------------------------------------------------ &lt;BR&gt;&lt;BR&gt;--Table&amp;nbsp;scan&amp;nbsp;will&amp;nbsp;be&amp;nbsp;used&amp;nbsp;for&amp;nbsp;both&amp;nbsp;because&amp;nbsp;of&amp;nbsp;execution&amp;nbsp;plan&amp;nbsp;re-use &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;DBCC&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;FREEPROCCACHE &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;EXEC&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:darkred;"&gt;sp_executesql&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:red;"&gt;N'SELECT&amp;nbsp;FirstName,&amp;nbsp;LastName,&amp;nbsp;PersonType,&amp;nbsp;Title &lt;BR&gt;FROM&amp;nbsp;p &lt;BR&gt;WHERE&amp;nbsp;LastName&amp;nbsp;=&amp;nbsp;@P1'&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;, &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:red;"&gt;N'@P1&amp;nbsp;nvarchar(50)'&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:red;"&gt;'Diaz' &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:green;"&gt;--20183&amp;nbsp;rows,&amp;nbsp;table&amp;nbsp;scan,&amp;nbsp;7612&amp;nbsp;pages &lt;BR&gt;&lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;EXEC&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:darkred;"&gt;sp_executesql&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:red;"&gt;N'SELECT&amp;nbsp;FirstName,&amp;nbsp;LastName,&amp;nbsp;PersonType,&amp;nbsp;Title &lt;BR&gt;FROM&amp;nbsp;p &lt;BR&gt;WHERE&amp;nbsp;LastName&amp;nbsp;=&amp;nbsp;@P1'&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;, &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:red;"&gt;N'@P1&amp;nbsp;nvarchar(50)'&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:red;"&gt;'Gimmi' &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:green;"&gt;--1&amp;nbsp;row,&amp;nbsp;table&amp;nbsp;scan,&amp;nbsp;7612&amp;nbsp;pages &lt;BR&gt;&lt;BR&gt;--Other&amp;nbsp;way&amp;nbsp;around &lt;BR&gt;--Index&amp;nbsp;search&amp;nbsp;will&amp;nbsp;be&amp;nbsp;used&amp;nbsp;for&amp;nbsp;both&amp;nbsp;because&amp;nbsp;of&amp;nbsp;execution&amp;nbsp;plan&amp;nbsp;re-use &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;DBCC&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;FREEPROCCACHE &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;EXEC&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:darkred;"&gt;sp_executesql&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:red;"&gt;N'SELECT&amp;nbsp;FirstName,&amp;nbsp;LastName,&amp;nbsp;PersonType,&amp;nbsp;Title &lt;BR&gt;FROM&amp;nbsp;p &lt;BR&gt;WHERE&amp;nbsp;LastName&amp;nbsp;=&amp;nbsp;@P1'&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;, &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:red;"&gt;N'@P1&amp;nbsp;nvarchar(50)'&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:red;"&gt;'Gimmi' &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:green;"&gt;--1&amp;nbsp;row,&amp;nbsp;index&amp;nbsp;seek,&amp;nbsp;3&amp;nbsp;pages &lt;BR&gt;&lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;EXEC&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:darkred;"&gt;sp_executesql&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:red;"&gt;N'SELECT&amp;nbsp;FirstName,&amp;nbsp;LastName,&amp;nbsp;PersonType,&amp;nbsp;Title &lt;BR&gt;FROM&amp;nbsp;p &lt;BR&gt;WHERE&amp;nbsp;LastName&amp;nbsp;=&amp;nbsp;@P1'&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;, &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:red;"&gt;N'@P1&amp;nbsp;nvarchar(50)'&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:red;"&gt;'Diaz' &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:green;"&gt;--20183&amp;nbsp;rows,&amp;nbsp;index&amp;nbsp;seek,&amp;nbsp;20291&amp;nbsp;pages &lt;BR&gt;&lt;BR&gt;&lt;BR&gt;------------------------------------------------------------------ &lt;BR&gt;--Alternative&amp;nbsp;using&amp;nbsp;variable &lt;BR&gt;------------------------------------------------------------------ &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;DBCC&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;FREEPROCCACHE &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;DECLARE&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:#434343;"&gt;@P1&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;NVARCHAR&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;50&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;) &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;SET&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:#434343;"&gt;@P1&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;=&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:red;"&gt;'Diaz' &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;SELECT&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;FirstName&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;LastName&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;PersonType&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;Title &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;FROM&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;p &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;WHERE&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;LastName&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;=&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:#434343;"&gt;@P1 &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;GO &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:green;"&gt;--20183&amp;nbsp;rows,&amp;nbsp;index&amp;nbsp;seek,&amp;nbsp;20291&amp;nbsp;pages &lt;BR&gt;&lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;DBCC&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;FREEPROCCACHE &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;DECLARE&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:#434343;"&gt;@P1&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;NVARCHAR&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;50&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;) &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;SET&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:#434343;"&gt;@P1&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;=&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:red;"&gt;'Gimmi' &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;SELECT&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;FirstName&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;LastName&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;PersonType&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;Title &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;FROM&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;p &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;WHERE&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;LastName&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;=&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:#434343;"&gt;@P1 &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;GO &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:green;"&gt;--1&amp;nbsp;rows,&amp;nbsp;index&amp;nbsp;seek,&amp;nbsp;1&amp;nbsp;pages &lt;BR&gt;&lt;BR&gt;--Same&amp;nbsp;plan&amp;nbsp;even&amp;nbsp;though&amp;nbsp;very&amp;nbsp;different&amp;nbsp;selectivity &lt;BR&gt;--and&amp;nbsp;emptying&amp;nbsp;plan&amp;nbsp;cache&amp;nbsp;in&amp;nbsp;between &lt;BR&gt;&lt;BR&gt;--Estimated&amp;nbsp;33&amp;nbsp;rows&amp;nbsp;for&amp;nbsp;both&amp;nbsp;above. &lt;BR&gt;--See&amp;nbsp;if&amp;nbsp;that&amp;nbsp;is&amp;nbsp;drawn&amp;nbsp;from&amp;nbsp;statistics&amp;nbsp;density? &lt;BR&gt;&lt;BR&gt;--Formula&amp;nbsp;for&amp;nbsp;density:&amp;nbsp;1/#OfUniqueValuesInColumn &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;SELECT&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;1.&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR:magenta;"&gt;COUNT&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;DISTINCT&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;LastName&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;)&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;FROM&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;p &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:green;"&gt;--0.00082918739 &lt;BR&gt;&lt;BR&gt;--Does&amp;nbsp;that&amp;nbsp;match&amp;nbsp;density&amp;nbsp;in&amp;nbsp;index&amp;nbsp;statistics? &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;DBCC&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;SHOW_STATISTICS&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="COLOR:red;"&gt;'p'&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:red;"&gt;'x'&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;) &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:green;"&gt;--Yes &lt;BR&gt;&lt;BR&gt;--How&amp;nbsp;many&amp;nbsp;rows&amp;nbsp;in&amp;nbsp;the&amp;nbsp;table? &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;SELECT&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:magenta;"&gt;COUNT&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(*)&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;FROM&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;p &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:green;"&gt;--39944 &lt;BR&gt;&lt;BR&gt;--So&amp;nbsp;how&amp;nbsp;many&amp;nbsp;rows&amp;nbsp;would&amp;nbsp;we&amp;nbsp;estimate&amp;nbsp;based&amp;nbsp;on&amp;nbsp;density? &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;SELECT&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;0.00082918739&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;*&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;39944 &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:green;"&gt;--Yep,&amp;nbsp;33&amp;nbsp;rows. &lt;BR&gt;&lt;BR&gt;--I.e,&amp;nbsp;for&amp;nbsp;the&amp;nbsp;variable&amp;nbsp;alternative,&amp;nbsp;SQL&amp;nbsp;Server&amp;nbsp;has&amp;nbsp;no&amp;nbsp; &lt;BR&gt;--knowledge&amp;nbsp;of&amp;nbsp;contents&amp;nbsp;of&amp;nbsp;those&amp;nbsp;variables&amp;nbsp;so&amp;nbsp;it&amp;nbsp;must&amp;nbsp;use&amp;nbsp;density&amp;nbsp;instead. &lt;BR&gt;&lt;BR&gt;--Clean&amp;nbsp;up: &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;IF&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:magenta;"&gt;OBJECT_ID&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="COLOR:red;"&gt;'p'&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;)&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;IS&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;NOT&amp;nbsp;NULL&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;DROP&amp;nbsp;TABLE&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;"&gt;p &lt;BR&gt;&lt;/SPAN&gt;&lt;/CODE&gt;
&lt;BR&gt;&lt;div class = "shareblock"&gt;&lt;span class = "shareblockTitle"&gt;Share this post:&lt;/span&gt;&lt;span class = "shareblockLink"&gt; &lt;a href = "mailto:?subject=Execution plan re-use, sp_executesql and TSQL variables&amp;amp;body=Seen on SQLblog.com: %0A%0A%09Execution plan re-use, sp_executesql and TSQL variables%0A%0Ahttp://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/29/execution-plan-re-use-sp-executesql-and-tsql-variables.aspx" target="_blank" title = "Email Execution plan re-use, sp_executesql and TSQL variables"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/29/execution-plan-re-use-sp-executesql-and-tsql-variables.aspx&amp;amp;title=Execution+plan+re-use%2c+sp_executesql+and+TSQL+variables" target="_blank" title = "Submit Execution plan re-use, sp_executesql and TSQL variables to del.icio.us"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/29/execution-plan-re-use-sp-executesql-and-tsql-variables.aspx&amp;amp;phase=2" target="_blank" title = "Submit Execution plan re-use, sp_executesql and TSQL variables to digg.com"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/29/execution-plan-re-use-sp-executesql-and-tsql-variables.aspx&amp;amp;title=Execution+plan+re-use%2c+sp_executesql+and+TSQL+variables" target="_blank" title = "Submit Execution plan re-use, sp_executesql and TSQL variables to reddit.com"&gt;reddit!&lt;/a&gt; |  &lt;a href = "http://www.dotnetkicks.com/submit/?url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/29/execution-plan-re-use-sp-executesql-and-tsql-variables.aspx&amp;amp;title=Execution+plan+re-use%2c+sp_executesql+and+TSQL+variables" target="_blank" title = "Submit Execution plan re-use, sp_executesql and TSQL variables to DotNetKicks"&gt;kick it!&lt;/a&gt; |  &lt;a href = "https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;mkt=en-us&amp;amp;url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/29/execution-plan-re-use-sp-executesql-and-tsql-variables.aspx&amp;amp;title=Execution+plan+re-use%2c+sp_executesql+and+TSQL+variables&amp;amp;;top=1" target="_blank" title = "Add Execution plan re-use, sp_executesql and TSQL variables to Live Bookmarks"&gt;live it!&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;img src="http://info.sqlblog.com/a.aspx?ZoneID=0&amp;BannerID=12&amp;AdvertiserID=1&amp;CampaignID=12&amp;Task=Get&amp;Mode=TEXT&amp;SiteID=1&amp;RandomNumber=463323" width="1" height="1" border="0"&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=8644" width="1" height="1"&gt;</content><author><name>TiborKaraszi</name><uri>http://sqlblog.com/members/TiborKaraszi.aspx</uri></author><category term="Performance" scheme="http://sqlblog.com/blogs/tibor_karaszi/archive/tags/Performance/default.aspx" /><category term="indexes" scheme="http://sqlblog.com/blogs/tibor_karaszi/archive/tags/indexes/default.aspx" /></entry><entry><title>Rebuilding msdb on SQL Server 2008</title><link rel="alternate" type="text/html" href="http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/27/rebuilding-msdb-on-sql-server-2008.aspx" /><id>http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/27/rebuilding-msdb-on-sql-server-2008.aspx</id><published>2008-08-27T10:10:00Z</published><updated>2008-08-27T10:10:00Z</updated><content type="html">&lt;P&gt;Because of the problems I had removing Data Collector I decided to rebuild msdb. You probably heard about instmsdb.sql, but it was a long time since I actually used it. I asked about rebuilding in the MVP group and Dan Jones (MS) pointed me to a Blog post from Paul Randal on how to do this on SQL Server 2005. Here's Paul's blog post:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/sqlserverstorageengine/archive/2006/06/06/619304.aspx"&gt;http://blogs.msdn.com/sqlserverstorageengine/archive/2006/06/06/619304.aspx&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Since above is for SQL Server 2005 I realized that it might not work smoothly on 2008. And It didn't. Below are some of the things I discovered (also posted as a comment on Paul's blog). Read below in light of Paul's blog. I should also say that nowhere does Paul states that his instructions work on 2008. It was me taking a chance. :-)&lt;/P&gt;
&lt;DIV&gt;You need to add startup parameter -s &amp;lt;instancename&amp;gt; if it is a named instance. Now, this I knew, but for the sake of other potential readers...&lt;/DIV&gt;
&lt;DIV&gt;I initially started the instance from the Windows services applet by adding -T3608. That didn't allow for detaching msdb. So I started from an OS command prompt and also added -c. This allowed me to detach msdb.&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;I now ran instmsdb, but that produced a number of errors. Here are a few comments about some of them:&lt;/DIV&gt;
&lt;DIV&gt;* Complaints on xp_cmdshell. I did try enabling this first and then ran instmsdb again but same result.&lt;/DIV&gt;
&lt;DIV&gt;* Bunch of errors when creating various Data Collector objects. This wasn't good, because cleaning up DC was the reason to rebuild msdb in the frist place.&lt;/DIV&gt;
&lt;DIV&gt;* 3 errors about sp_configure and -1 wasn't allowed value (two for Agent Xps and one for xp_cmdshell).&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;Just for the sake of trying, I now tried to connect to the instance using SSMS Object Explorer. But I now got some error regarding Agent Xp's when connecting. I tried to explicitly enabling Agent XP's using sp_configure but same error. When connected there's no node in Objects Explorer for Agent. &lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;I took this as an indication that Agent isn't healthy. Whether it was me doing something fishy or it isn't as easy as just running insmsdb.sql for SQL Server 2008 - I don't know. But I'm in for a rebuild of system databases. This isn't that bad since it is a just a test machine. But these issues might serve as example why you want to follow Paul's initial advice: always backup msdb (also on test machines).&lt;/DIV&gt;
&lt;BR&gt;&lt;div class = "shareblock"&gt;&lt;span class = "shareblockTitle"&gt;Share this post:&lt;/span&gt;&lt;span class = "shareblockLink"&gt; &lt;a href = "mailto:?subject=Rebuilding msdb on SQL Server 2008&amp;amp;body=Seen on SQLblog.com: %0A%0A%09Rebuilding msdb on SQL Server 2008%0A%0Ahttp://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/27/rebuilding-msdb-on-sql-server-2008.aspx" target="_blank" title = "Email Rebuilding msdb on SQL Server 2008"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/27/rebuilding-msdb-on-sql-server-2008.aspx&amp;amp;title=Rebuilding+msdb+on+SQL+Server+2008" target="_blank" title = "Submit Rebuilding msdb on SQL Server 2008 to del.icio.us"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/27/rebuilding-msdb-on-sql-server-2008.aspx&amp;amp;phase=2" target="_blank" title = "Submit Rebuilding msdb on SQL Server 2008 to digg.com"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/27/rebuilding-msdb-on-sql-server-2008.aspx&amp;amp;title=Rebuilding+msdb+on+SQL+Server+2008" target="_blank" title = "Submit Rebuilding msdb on SQL Server 2008 to reddit.com"&gt;reddit!&lt;/a&gt; |  &lt;a href = "http://www.dotnetkicks.com/submit/?url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/27/rebuilding-msdb-on-sql-server-2008.aspx&amp;amp;title=Rebuilding+msdb+on+SQL+Server+2008" target="_blank" title = "Submit Rebuilding msdb on SQL Server 2008 to DotNetKicks"&gt;kick it!&lt;/a&gt; |  &lt;a href = "https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;mkt=en-us&amp;amp;url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/27/rebuilding-msdb-on-sql-server-2008.aspx&amp;amp;title=Rebuilding+msdb+on+SQL+Server+2008&amp;amp;;top=1" target="_blank" title = "Add Rebuilding msdb on SQL Server 2008 to Live Bookmarks"&gt;live it!&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;img src="http://info.sqlblog.com/a.aspx?ZoneID=0&amp;BannerID=12&amp;AdvertiserID=1&amp;CampaignID=12&amp;Task=Get&amp;Mode=TEXT&amp;SiteID=1&amp;RandomNumber=463323" width="1" height="1" border="0"&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=8605" width="1" height="1"&gt;</content><author><name>TiborKaraszi</name><uri>http://sqlblog.com/members/TiborKaraszi.aspx</uri></author><category term="Backup" scheme="http://sqlblog.com/blogs/tibor_karaszi/archive/tags/Backup/default.aspx" /><category term="SQL Server 2008" scheme="http://sqlblog.com/blogs/tibor_karaszi/archive/tags/SQL+Server+2008/default.aspx" /></entry><entry><title>We've come a long way ...</title><link rel="alternate" type="text/html" href="http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/27/we-ve-come-a-long-way.aspx" /><id>http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/27/we-ve-come-a-long-way.aspx</id><published>2008-08-27T09:02:00Z</published><updated>2008-08-27T09:02:00Z</updated><content type="html">&lt;P&gt;For various reasons I decided that I want virtual machines with older (pre-2008) SQL Server versions available on my various machines. For me, virtualization (in this case VPC) is great:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;I rarely use these installs, most often I just boot it and check some detail.&lt;/LI&gt;
&lt;LI&gt;I don't have to litter the host OS.&lt;/LI&gt;
&lt;LI&gt;I don't pay anything (performance) in the host OS, except for some disk. The overhead for an extra XP install is some 1.5 GB which nowadays isn't that bad.&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;So I did a several copies of my XP VPC folder (I don't do diff drives for various reasons). &lt;/P&gt;
&lt;P&gt;And then started with installing SQL Server 2000 (I already had VPCs with 2005). I do work with 2000 now and then, but I mainly use SSMS to connect to 2000. So it was a bit of flashback to play around with EM again.&lt;/P&gt;
&lt;P&gt;Next was 7.0. OK, 7.0 didn't look that different from 2000...&lt;/P&gt;
&lt;P&gt;Installing 6.5 was more fun. I had forgot for instance that SQL Server Agent was called "SQL Executive" back then. Also, Enterprise Manager was a totally different tool compared to 7.0/2000. &lt;/P&gt;
&lt;P&gt;I decided to skip 6.0 since the 6.5 BOL is basically 6.0 BOL with added "What's new" section. So having above 6.5 VPC for me also covers 6.0.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;The most interesting part was to 4.21a for NT:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;I first realized I made a mistake when copying the files from diskettes to CD - I put all the files in same directory. Setup expects some folder structure like DISK1, DISK2 etc. And since I don't have the diskettes anymore, how to know what files go in which folder? What I ended up doing was to copy the setup files locally (a whopping 4.4 MB !) and&amp;nbsp;modify SETUP.INF. Interestingly enough I did figure out how to modify the INF file successfully. Imagine doing that today - without knowing anything about the installation...&lt;/P&gt;
&lt;P&gt;Anyhow, installation was successful and I checked out what tools we had. Hehe, this is where nostalgia kicked in. I already have a&amp;nbsp;OS/2 VPC with SQL Server 1.1, but I can barely navigate that OS nowadays. And there were no GUI's at all with SQL Server 1.x. Since I hadn't seen SQL Server 4.x for many many years now, I think this was more fun than re-living 1.1.&lt;/P&gt;
&lt;P&gt;What strikes you are of course the tools. Looking at the engine (using "Books Online") you mainly see that a lot of todays functionality wasn't there of course. But using the GUI makes it so much more&amp;nbsp;apparent what was there and what wasn't. And of course the whole feel of the GUIs were totally different.&lt;/P&gt;
&lt;P&gt;The help file start page has some 9 buttons, for various sections like Datatypes, Expressions, LIKE and Wildcards, Transact-SQL Statements etc. No tree-like structure...&lt;/P&gt;
&lt;P&gt;The release notes explain for instance that Extended stored procedures are a new thing and with that came SQL Mail.&lt;/P&gt;
&lt;P&gt;What we nowadays call SQL Server Agent was called "SQL Monitor".&lt;/P&gt;
&lt;P&gt;The "SQL Administrator Win32" tool had some very rudimentary dialogs for looking at "devices", "DB", "Login" etc. There are some dialogs available from the menus like "Database Consistency Check", "configure SQL Server". I could not find for instance where to schedule backups with SQL Monitor...&lt;/P&gt;
&lt;P&gt;The "SQL Object Manager Win32" tool&amp;nbsp;wasn't actually that bad. The "Objects" window list one row per object in the database and you can double-click it to "edit" it. Interesting enough I believe this is the first version where we had "Generate Script" functionality in the tools, for instance. Hehe, there's even a GUI for assisting in creating a SELECT statement with rows allowing you to type text for the WHERE clause, the ORDER BY clause&amp;nbsp;etc.&lt;/P&gt;
&lt;P&gt;There's a separate tool called "SQL Transfer Manager" which functionality over the years have been exposed in various places (EM, DTS, SSIS, DMO, SMO etc).&lt;/P&gt;
&lt;P&gt;Back to reality. Firing up SSMS 2008 I realize how much has changed... The engine has so much more functionality. Perhaps only, say, 10-15% of what we have today we also had in, say, 4.x - if even that. Not to mention things like SSAS, SSIS, RS, etc. So, even though it was&amp;nbsp;fun nostalgia to fire up an old version, I really enjoy being where we are today. :-)&lt;/P&gt;
&lt;BR&gt;&lt;div class = "shareblock"&gt;&lt;span class = "shareblockTitle"&gt;Share this post:&lt;/span&gt;&lt;span class = "shareblockLink"&gt; &lt;a href = "mailto:?subject=We've come a long way ...&amp;amp;body=Seen on SQLblog.com: %0A%0A%09We've come a long way ...%0A%0Ahttp://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/27/we-ve-come-a-long-way.aspx" target="_blank" title = "Email We've come a long way ..."&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/27/we-ve-come-a-long-way.aspx&amp;amp;title=We%27ve+come+a+long+way+..." target="_blank" title = "Submit We've come a long way ... to del.icio.us"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/27/we-ve-come-a-long-way.aspx&amp;amp;phase=2" target="_blank" title = "Submit We've come a long way ... to digg.com"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/27/we-ve-come-a-long-way.aspx&amp;amp;title=We%27ve+come+a+long+way+..." target="_blank" title = "Submit We've come a long way ... to reddit.com"&gt;reddit!&lt;/a&gt; |  &lt;a href = "http://www.dotnetkicks.com/submit/?url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/27/we-ve-come-a-long-way.aspx&amp;amp;title=We%27ve+come+a+long+way+..." target="_blank" title = "Submit We've come a long way ... to DotNetKicks"&gt;kick it!&lt;/a&gt; |  &lt;a href = "https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;mkt=en-us&amp;amp;url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/27/we-ve-come-a-long-way.aspx&amp;amp;title=We%27ve+come+a+long+way+...&amp;amp;;top=1" target="_blank" title = "Add We've come a long way ... to Live Bookmarks"&gt;live it!&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;img src="http://info.sqlblog.com/a.aspx?ZoneID=0&amp;BannerID=12&amp;AdvertiserID=1&amp;CampaignID=12&amp;Task=Get&amp;Mode=TEXT&amp;SiteID=1&amp;RandomNumber=463323" width="1" height="1" border="0"&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=8604" width="1" height="1"&gt;</content><author><name>TiborKaraszi</name><uri>http://sqlblog.com/members/TiborKaraszi.aspx</uri></author><category term="Nostalgia" scheme="http://sqlblog.com/blogs/tibor_karaszi/archive/tags/Nostalgia/default.aspx" /></entry><entry><title>Missing F8 or ctrl-N in SSMS 2008?</title><link rel="alternate" type="text/html" href="http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/26/missing-f8-or-ctrl-n-in-ssms-2008.aspx" /><id>http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/26/missing-f8-or-ctrl-n-in-ssms-2008.aspx</id><published>2008-08-26T07:22:00Z</published><updated>2008-08-26T07:22:00Z</updated><content type="html">&lt;P&gt;Short story: Turn on 2000 keyboard layout and then&amp;nbsp;back to Standard layout.&lt;/P&gt;
&lt;P&gt;Long story:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This topic has been discussed in both the MCT (MS Certified Trainer) as well as MVP groups. Also, see &lt;A href="http://sqlblog.com/blogs/andy_leonard/archive/2008/08/08/sql-server-2008-management-studio-function-keys.aspx"&gt;http://sqlblog.com/blogs/andy_leonard/archive/2008/08/08/sql-server-2008-management-studio-function-keys.aspx&lt;/A&gt;, including the comments.&lt;/P&gt;
&lt;P&gt;The mystery seems to be that in some cases you do have F8 and Ctrl-N in Standard layout, where in other cases you don't. For instance I did a check on&amp;nbsp;4 installations where one had the desired layout (with F8) and the others didn't:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;VPC. XP. Clean install. No prior SQL Server stuff. No F8 or ctrl-N.&lt;/LI&gt;
&lt;LI&gt;My laptop, XP. I have 2000, 2005 and 2008 tools as well as 2000, 2005 and 2008 instances installed. No F8 or ctrl-N.&lt;/LI&gt;
&lt;LI&gt;My desktop machine, Vista. I have 2005 and also 2008 instances. I have had 2005 SSMS which was uninstalled before I installed 2008 SSMS. Here both ctrl-N and F8 work.&lt;/LI&gt;
&lt;LI&gt;VPC. XP. Had 2005 both tools and instance which were upgraded to 2008. No F8 or ctrl-N.&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;I was doing training on 2008 last week and I really needed to find my shortcut keys (I couldn't keep stumbling after menus all the time - too slow). So I switched to what I'm familiar with: the 2000 keyboard layout. I recall thinking for myself that perhaps if I now switch back I will have the desired Standard layout (F8 and Ctrl-N). I forgot all about it until today reading a post in the MVP group from Craig Beere suggesting exactly this. To confirm, I tried this in both a virtual machine (1 above) as well as my laptop (2 above) and it worked indeed. &lt;/P&gt;
&lt;P&gt;One thing to watch out for: There doesn't seem to be a way to go back to Standard layout *without* F8 and Ctrl-N. For instance when you get F8 etc, you also get a different shortcut for comment code (or was it uncomment?). So you might want to think a little bit before setting to 2000 layout and back. I'm sure in the end that somebody finds a setting somewhere to control the behavior - and then we know how to switch between the two Standard alternatives...&lt;/P&gt;
&lt;BR&gt;&lt;div class = "shareblock"&gt;&lt;span class = "shareblockTitle"&gt;Share this post:&lt;/span&gt;&lt;span class = "shareblockLink"&gt; &lt;a href = "mailto:?subject=Missing F8 or ctrl-N in SSMS 2008?&amp;amp;body=Seen on SQLblog.com: %0A%0A%09Missing F8 or ctrl-N in SSMS 2008?%0A%0Ahttp://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/26/missing-f8-or-ctrl-n-in-ssms-2008.aspx" target="_blank" title = "Email Missing F8 or ctrl-N in SSMS 2008?"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/26/missing-f8-or-ctrl-n-in-ssms-2008.aspx&amp;amp;title=Missing+F8+or+ctrl-N+in+SSMS+2008%3f" target="_blank" title = "Submit Missing F8 or ctrl-N in SSMS 2008? to del.icio.us"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/26/missing-f8-or-ctrl-n-in-ssms-2008.aspx&amp;amp;phase=2" target="_blank" title = "Submit Missing F8 or ctrl-N in SSMS 2008? to digg.com"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/26/missing-f8-or-ctrl-n-in-ssms-2008.aspx&amp;amp;title=Missing+F8+or+ctrl-N+in+SSMS+2008%3f" target="_blank" title = "Submit Missing F8 or ctrl-N in SSMS 2008? to reddit.com"&gt;reddit!&lt;/a&gt; |  &lt;a href = "http://www.dotnetkicks.com/submit/?url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/26/missing-f8-or-ctrl-n-in-ssms-2008.aspx&amp;amp;title=Missing+F8+or+ctrl-N+in+SSMS+2008%3f" target="_blank" title = "Submit Missing F8 or ctrl-N in SSMS 2008? to DotNetKicks"&gt;kick it!&lt;/a&gt; |  &lt;a href = "https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;mkt=en-us&amp;amp;url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/26/missing-f8-or-ctrl-n-in-ssms-2008.aspx&amp;amp;title=Missing+F8+or+ctrl-N+in+SSMS+2008%3f&amp;amp;;top=1" target="_blank" title = "Add Missing F8 or ctrl-N in SSMS 2008? to Live Bookmarks"&gt;live it!&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;img src="http://info.sqlblog.com/a.aspx?ZoneID=0&amp;BannerID=12&amp;AdvertiserID=1&amp;CampaignID=12&amp;Task=Get&amp;Mode=TEXT&amp;SiteID=1&amp;RandomNumber=463323" width="1" height="1" border="0"&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=8567" width="1" height="1"&gt;</content><author><name>TiborKaraszi</name><uri>http://sqlblog.com/members/TiborKaraszi.aspx</uri></author><category term="Tools" scheme="http://sqlblog.com/blogs/tibor_karaszi/archive/tags/Tools/default.aspx" /><category term="SQL Server 2008" scheme="http://sqlblog.com/blogs/tibor_karaszi/archive/tags/SQL+Server+2008/default.aspx" /></entry><entry><title>Make sure you play with data collector on a virtual machine</title><link rel="alternate" type="text/html" href="http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/25/make-sure-you-play-with-data-collector-on-a-virtual-machine.aspx" /><id>http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/25/make-sure-you-play-with-data-collector-on-a-virtual-machine.aspx</id><published>2008-08-25T16:42:00Z</published><updated>2008-08-25T16:42:00Z</updated><content type="html">&lt;P&gt;I'm in a situation where I have configured the new data collector functionality for three instances. And there's no way to undo the config performed by the wizard! It cannot be undone by the wizard, and BOL doesn't have information on how to do this. In fact, I suspect that you in the&amp;nbsp;end need to use some of the undocumented data collector procedures to get rid of this configuration (like sp_syscollector_delete_jobs).&lt;/P&gt;
&lt;P&gt;I'm not knocking data collector per se - it seems like a great way to get a baseline going etc. But my tip is that while you are playing with it in order to understand it - do it virtually.&lt;/P&gt;
&lt;P&gt;Lara has reported this on connect, btw: &lt;A href="https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=334180"&gt;https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=334180&lt;/A&gt;&lt;/P&gt;
&lt;BR&gt;&lt;div class = "shareblock"&gt;&lt;span class = "shareblockTitle"&gt;Share this post:&lt;/span&gt;&lt;span class = "shareblockLink"&gt; &lt;a href = "mailto:?subject=Make sure you play with data collector on a virtual machine&amp;amp;body=Seen on SQLblog.com: %0A%0A%09Make sure you play with data collector on a virtual machine%0A%0Ahttp://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/25/make-sure-you-play-with-data-collector-on-a-virtual-machine.aspx" target="_blank" title = "Email Make sure you play with data collector on a virtual machine"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/25/make-sure-you-play-with-data-collector-on-a-virtual-machine.aspx&amp;amp;title=Make+sure+you+play+with+data+collector+on+a+virtual+machine" target="_blank" title = "Submit Make sure you play with data collector on a virtual machine to del.icio.us"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/25/make-sure-you-play-with-data-collector-on-a-virtual-machine.aspx&amp;amp;phase=2" target="_blank" title = "Submit Make sure you play with data collector on a virtual machine to digg.com"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/25/make-sure-you-play-with-data-collector-on-a-virtual-machine.aspx&amp;amp;title=Make+sure+you+play+with+data+collector+on+a+virtual+machine" target="_blank" title = "Submit Make sure you play with data collector on a virtual machine to reddit.com"&gt;reddit!&lt;/a&gt; |  &lt;a href = "http://www.dotnetkicks.com/submit/?url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/25/make-sure-you-play-with-data-collector-on-a-virtual-machine.aspx&amp;amp;title=Make+sure+you+play+with+data+collector+on+a+virtual+machine" target="_blank" title = "Submit Make sure you play with data collector on a virtual machine to DotNetKicks"&gt;kick it!&lt;/a&gt; |  &lt;a href = "https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;mkt=en-us&amp;amp;url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/25/make-sure-you-play-with-data-collector-on-a-virtual-machine.aspx&amp;amp;title=Make+sure+you+play+with+data+collector+on+a+virtual+machine&amp;amp;;top=1" target="_blank" title = "Add Make sure you play with data collector on a virtual machine to Live Bookmarks"&gt;live it!&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;img src="http://info.sqlblog.com/a.aspx?ZoneID=0&amp;BannerID=12&amp;AdvertiserID=1&amp;CampaignID=12&amp;Task=Get&amp;Mode=TEXT&amp;SiteID=1&amp;RandomNumber=463323" width="1" height="1" border="0"&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=8549" width="1" height="1"&gt;</content><author><name>TiborKaraszi</name><uri>http://sqlblog.com/members/TiborKaraszi.aspx</uri></author><category term="Tools" scheme="http://sqlblog.com/blogs/tibor_karaszi/archive/tags/Tools/default.aspx" /><category term="Performance" scheme="http://sqlblog.com/blogs/tibor_karaszi/archive/tags/Performance/default.aspx" /><category term="SQL Server 2008" scheme="http://sqlblog.com/blogs/tibor_karaszi/archive/tags/SQL+Server+2008/default.aspx" /></entry><entry><title>Updates of Ola Hallengren's maint procedures</title><link rel="alternate" type="text/html" href="http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/23/updates-of-ola-hallengren-s-maint-procedures.aspx" /><id>http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/23/updates-of-ola-hallengren-s-maint-procedures.aspx</id><published>2008-08-23T07:49:00Z</published><updated>2008-08-23T07:49:00Z</updated><content type="html">&lt;P&gt;Ola Hallengren has updated his maint procedures. Support for SQL Server 2008 and some bug fixes. Check them out at:&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Calibri','sans-serif';mso-ascii-theme-font:minor-latin;mso-fareast-font-family:Calibri;mso-fareast-theme-font:minor-latin;mso-hansi-theme-font:minor-latin;mso-bidi-font-family:'Times New Roman';mso-bidi-theme-font:minor-bidi;mso-ansi-language:SV;mso-fareast-language:EN-US;mso-bidi-language:AR-SA;"&gt;&lt;A href="http://blog.ola.hallengren.com/blog/_archives/2008/1/1/3440068.html"&gt;http://blog.ola.hallengren.com/blog/_archives/2008/1/1/3440068.html&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;BR&gt;&lt;div class = "shareblock"&gt;&lt;span class = "shareblockTitle"&gt;Share this post:&lt;/span&gt;&lt;span class = "shareblockLink"&gt; &lt;a href = "mailto:?subject=Updates of Ola Hallengren's maint procedures&amp;amp;body=Seen on SQLblog.com: %0A%0A%09Updates of Ola Hallengren's maint procedures%0A%0Ahttp://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/23/updates-of-ola-hallengren-s-maint-procedures.aspx" target="_blank" title = "Email Updates of Ola Hallengren's maint procedures"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/23/updates-of-ola-hallengren-s-maint-procedures.aspx&amp;amp;title=Updates+of+Ola+Hallengren%27s+maint+procedures" target="_blank" title = "Submit Updates of Ola Hallengren's maint procedures to del.icio.us"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/23/updates-of-ola-hallengren-s-maint-procedures.aspx&amp;amp;phase=2" target="_blank" title = "Submit Updates of Ola Hallengren's maint procedures to digg.com"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/23/updates-of-ola-hallengren-s-maint-procedures.aspx&amp;amp;title=Updates+of+Ola+Hallengren%27s+maint+procedures" target="_blank" title = "Submit Updates of Ola Hallengren's maint procedures to reddit.com"&gt;reddit!&lt;/a&gt; |  &lt;a href = "http://www.dotnetkicks.com/submit/?url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/23/updates-of-ola-hallengren-s-maint-procedures.aspx&amp;amp;title=Updates+of+Ola+Hallengren%27s+maint+procedures" target="_blank" title = "Submit Updates of Ola Hallengren's maint procedures to DotNetKicks"&gt;kick it!&lt;/a&gt; |  &lt;a href = "https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;mkt=en-us&amp;amp;url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/23/updates-of-ola-hallengren-s-maint-procedures.aspx&amp;amp;title=Updates+of+Ola+Hallengren%27s+maint+procedures&amp;amp;;top=1" target="_blank" title = "Add Updates of Ola Hallengren's maint procedures to Live Bookmarks"&gt;live it!&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;img src="http://info.sqlblog.com/a.aspx?ZoneID=0&amp;BannerID=12&amp;AdvertiserID=1&amp;CampaignID=12&amp;Task=Get&amp;Mode=TEXT&amp;SiteID=1&amp;RandomNumber=463323" width="1" height="1" border="0"&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=8504" width="1" height="1"&gt;</content><author><name>TiborKaraszi</name><uri>http://sqlblog.com/members/TiborKaraszi.aspx</uri></author><category term="Maintenance" scheme="http://sqlblog.com/blogs/tibor_karaszi/archive/tags/Maintenance/default.aspx" /></entry><entry><title>Are inserts quicker to heap or clustered tables?</title><link rel="alternate" type="text/html" href="http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/14/are-inserts-quicker-to-heap-or-clustered-tables.aspx" /><id>http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/14/are-inserts-quicker-to-heap-or-clustered-tables.aspx</id><published>2008-08-14T12:05:00Z</published><updated>2008-08-14T12:05:00Z</updated><content type="html">&lt;P&gt;Is it quicker and/or lower overhead to insert into a heap vs. a clustered table?&lt;BR&gt;I don't know. So I decided to do a test. Some background information first:&lt;/P&gt;
&lt;P&gt;The test was inspired from a sidebar with Gert-Jan Strik in the open newsgroups. Basically I expressed that a heap doesn't automatically carry lower overhead... just because it is a heap. Now, heaps vs. clustered tables is a huge topic with many aspects. I will not cover anything else here except inserts into a heap vs. a table which is clustered on an ever increasing key. No other indexes. There will be no fragmentation. I do not cover searches, covering etc. Only the pure insert aspect. OK? Good!&lt;/P&gt;
&lt;P&gt;One might think that a heap has lower overhead because it is a ... heap. But hang on for a second and think about what happens when you do an insert:&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Heap:&lt;BR&gt;&lt;/STRONG&gt;SQL Server need to find where the row should go. For this it uses one or more IAM pages for the heap, and it cross references these to one or more PFS pages for the database file(s). IMO, there should be potential for a noticable overhead here. And even more, with many users hammering the same table I can imagine blocking (waits) against the PFS and possibly also IAM pages.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Clustered table:&lt;BR&gt;&lt;/STRONG&gt;Now, this is dead simple. SQL server navigates the clustered index tree and find where the row should go. Since this is an ever increasing index key, each row will go to the end of the table (linked list).&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;The result:&lt;BR&gt;&lt;/STRONG&gt;So what is the conclusion? I did several executions of the code at the end of this post, with some variations. Basically there was no or very little difference whith only one user. I.e., no contention to the GAM or PFS pages. This was pretty consistent for below three scenarios:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Insert with subselect. I.e., this inserts lots of rows in the same statement.&lt;/LI&gt;
&lt;LI&gt;Insert in a loop (one insert and row per iteration), many rows in the same transaction.&lt;/LI&gt;
&lt;LI&gt;Insert in a loop, one row per transaction.&amp;nbsp;&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;Now the difference between 2 and 3 is important. &lt;BR&gt;With many transactions, we incur an overhead of force-log-write-at-commit *for each row*. I.e., much more overhead against the transaction log. And indeed, the timings between 2 and 3 for one of my executions (10000 rows) showed that 2 took on average 650 ms where the same number for 3 was 5600 ms. This is about 9 times longer!!! Now, this was more or less expected, but another important aspect is when we have several users. With many users, we might run into blocking on the PFS and IAM pages. Also, with several users it is meaningless to do it all in one transaction since we will block and essentially single-thread the code anyhow. I.e., the only revelant measure where we run many users is the loop construction where each row is its own transaction (3).&lt;/P&gt;
&lt;P&gt;There was indded a noticeable difference when I executed several inserts in parallell and had each insert in its own transaction (for clustered table vs. heap table). &lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Some numbers:&lt;BR&gt;&lt;/STRONG&gt;I did 4 repeated tests&amp;nbsp;and calculated average execution time for inserting 10000 rows for a thread. With 6 parallel thread I had 22 seconds for a clustered table and 29 seconds for a heap table. With 10 threads I had 31 seconds for a clustered table and 42 seconds for a heap table. &lt;/P&gt;
&lt;P&gt;I didn't find performance difference more than a couple of percents for batch inserts, when I single threaded (only one thread pumping inserts), or when I had all inserts in the loop as one transaction.&lt;/P&gt;
&lt;P&gt;Now, I would need lots of more time to run exchaustive tests, but my interpretation is that with many users doing inserts, there is an noticable overhead for the heap vs clustering on a increasing key.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;The code:&lt;/STRONG&gt;&lt;BR&gt;Note that for parallell executions, I recommend starting the DoTheInserts procedure using SQLCMD, a BAT file and START. As always, read the code carefully (so you understand it) and execute at your own risk.&lt;/P&gt;
&lt;P&gt;--------------------------------------------&lt;BR&gt;--Create the database etc.&lt;BR&gt;--------------------------------------------&lt;BR&gt;USE master SET NOCOUNT ON&lt;BR&gt;GO&lt;BR&gt;IF DB_ID('TestDb') IS NOT NULL DROP DATABASE TestDb&lt;BR&gt;GO&lt;BR&gt;--Makes files large enough so that inserts don't causes autogrow&lt;BR&gt;CREATE DATABASE TestDb&lt;BR&gt;ON&amp;nbsp; PRIMARY &lt;BR&gt;(NAME = 'TestDb', FILENAME = 'C:\TestDb.mdf', SIZE = 300MB, FILEGROWTH = 50MB)&lt;BR&gt;LOG ON &lt;BR&gt;(NAME = 'TestDb_log', FILENAME = 'C:\TestDb_log.ldf', SIZE = 200MB, FILEGROWTH = 100MB)&lt;BR&gt;GO&lt;BR&gt;--Full recovery to avoid effect of system caused log truncation&lt;BR&gt;ALTER DATABASE TestDb SET RECOVERY FULL&lt;BR&gt;BACKUP DATABASE TestDb TO DISK = 'nul'&lt;BR&gt;USE TestDb&lt;/P&gt;
&lt;P&gt;--Execution time log table&lt;BR&gt;IF OBJECT_ID('TimeLogger') IS NOT NULL DROP TABLE TimeLogger&lt;BR&gt;GO&lt;BR&gt;CREATE TABLE TimeLogger&lt;BR&gt;(&lt;BR&gt;&amp;nbsp;SomeId int identity&lt;BR&gt;,spid int&lt;BR&gt;,TableStructure varchar(10) CHECK (TableStructure IN ('heap', 'clustered'))&lt;BR&gt;,InsertType varchar(20) CHECK (InsertType IN('one statement', 'loop'))&lt;BR&gt;,ExecutionTimeMs int&lt;BR&gt;)&lt;BR&gt;GO&lt;/P&gt;
&lt;P&gt;IF OBJECT_ID('RowsToInsert') IS NOT NULL DROP TABLE RowsToInsert&lt;BR&gt;CREATE TABLE RowsToInsert(#rows int)&lt;BR&gt;GO&lt;/P&gt;
&lt;P&gt;--Support procedures&lt;BR&gt;IF OBJECT_ID('CreateTables') IS NOT NULL DROP PROC CreateTables&lt;BR&gt;GO&lt;BR&gt;CREATE PROC CreateTables AS&lt;BR&gt;IF OBJECT_ID('HeapLoop') IS NOT NULL DROP TABLE HeapLoop&lt;BR&gt;CREATE TABLE HeapLoop(c1 int identity, c2 int DEFAULT 2, c3 datetime DEFAULT GETDATE(), c4 char(200) DEFAULT 'g')&lt;BR&gt;IF OBJECT_ID('ClusteredLoop') IS NOT NULL DROP TABLE ClusteredLoop&lt;BR&gt;CREATE TABLE ClusteredLoop(c1 int identity, c2 int DEFAULT 2, c3 datetime DEFAULT GETDATE(), c4 char(200) DEFAULT 'g')&lt;BR&gt;CREATE CLUSTERED INDEX x ON ClusteredLoop(c1)&lt;BR&gt;IF OBJECT_ID('HeapOneStatement') IS NOT NULL DROP TABLE HeapOneStatement&lt;BR&gt;CREATE TABLE HeapOneStatement(c1 int identity, c2 int DEFAULT 2, c3 datetime DEFAULT GETDATE(), c4 char(200) DEFAULT 'g')&lt;BR&gt;IF OBJECT_ID('ClusteredOneStatement') IS NOT NULL DROP TABLE ClusteredOneStatement&lt;BR&gt;CREATE TABLE ClusteredOneStatement(c1 int identity, c2 int DEFAULT 2, c3 datetime DEFAULT GETDATE(), c4 char(200) DEFAULT 'g')&lt;BR&gt;CREATE CLUSTERED INDEX x ON ClusteredOneStatement(c1)&lt;BR&gt;GO&lt;/P&gt;
&lt;P&gt;IF OBJECT_ID('TruncateTables') IS NOT NULL DROP PROC TruncateTables&lt;BR&gt;GO&lt;BR&gt;CREATE PROC TruncateTables AS&lt;BR&gt;TRUNCATE TABLE HeapLoop&lt;BR&gt;TRUNCATE TABLE ClusteredLoop&lt;BR&gt;TRUNCATE TABLE HeapOneStatement&lt;BR&gt;TRUNCATE TABLE ClusteredOneStatement&lt;BR&gt;GO&lt;/P&gt;
&lt;P&gt;IF OBJECT_ID('DoBefore') IS NOT NULL DROP PROC DoBefore&lt;BR&gt;GO&lt;BR&gt;CREATE PROC DoBefore AS&lt;BR&gt;BACKUP LOG TestDb TO DISK = 'nul'&lt;BR&gt;CHECKPOINT&lt;BR&gt;GO&lt;/P&gt;
&lt;P&gt;IF OBJECT_ID('iHeapLoop') IS NOT NULL DROP PROC iHeapLoop&lt;BR&gt;GO&lt;BR&gt;CREATE PROC iHeapLoop @rows int AS&lt;BR&gt;DECLARE @i int = 1&lt;BR&gt;WHILE @i &amp;lt;= @rows&lt;BR&gt;BEGIN&lt;BR&gt;&amp;nbsp;INSERT INTO HeapLoop (c2) VALUES(2)&lt;BR&gt;&amp;nbsp;SET @i = @i + 1&lt;BR&gt;END&lt;BR&gt;GO&lt;/P&gt;
&lt;P&gt;IF OBJECT_ID('iClusteredLoop') IS NOT NULL DROP PROC iClusteredLoop&lt;BR&gt;GO&lt;BR&gt;CREATE PROC iClusteredLoop @rows int AS&lt;BR&gt;DECLARE @i int = 1&lt;BR&gt;WHILE @i &amp;lt;= @rows&lt;BR&gt;BEGIN&lt;BR&gt;&amp;nbsp;INSERT INTO ClusteredLoop (c2) VALUES(2)&lt;BR&gt;&amp;nbsp;SET @i = @i + 1&lt;BR&gt;END&lt;BR&gt;GO&lt;/P&gt;
&lt;P&gt;IF OBJECT_ID('iHeapOneStatement') IS NOT NULL DROP PROC iHeapOneStatement&lt;BR&gt;GO&lt;BR&gt;CREATE PROC iHeapOneStatement @rows int AS&lt;BR&gt;INSERT INTO HeapOneStatement (c2)&lt;BR&gt;SELECT TOP(@rows) 2 FROM syscolumns a CROSS JOIN syscolumns b&lt;BR&gt;GO&lt;/P&gt;
&lt;P&gt;IF OBJECT_ID('iClusteredOneStatement') IS NOT NULL DROP PROC iClusteredOneStatement&lt;BR&gt;GO&lt;BR&gt;CREATE PROC iClusteredOneStatement @rows int AS &lt;BR&gt;INSERT INTO ClusteredOneStatement (c2)&lt;BR&gt;SELECT TOP(@rows) 2 FROM syscolumns a CROSS JOIN syscolumns b&lt;BR&gt;GO&lt;/P&gt;
&lt;P&gt;--Proc to do the inserts&lt;BR&gt;IF OBJECT_ID('DoTheInserts') IS NOT NULL DROP PROC DoTheInserts&lt;BR&gt;GO&lt;BR&gt;CREATE PROC DoTheInserts&lt;BR&gt;AS&lt;BR&gt;DECLARE @dt datetime, @NumberOfRowsToInsert int&lt;BR&gt;SET @NumberOfRowsToInsert = (SELECT #rows FROM RowsToInsert)&lt;BR&gt;EXEC DoBefore --Batch allocation, heap:&lt;BR&gt;SET @dt = GETDATE()&lt;BR&gt;EXEC iHeapOneStatement @rows = @NumberOfRowsToInsert&lt;BR&gt;INSERT INTO TimeLogger (spid, TableStructure, InsertType, ExecutionTimeMs)&lt;BR&gt;VALUES(@@SPID, 'heap', 'one statement', DATEDIFF(ms, @dt, GETDATE()))&lt;/P&gt;
&lt;P&gt;EXEC DoBefore --Batch allocation, clustered:&lt;BR&gt;SET @dt = GETDATE()&lt;BR&gt;EXEC iClusteredOneStatement @rows = @NumberOfRowsToInsert&lt;BR&gt;INSERT INTO TimeLogger (spid, TableStructure, InsertType, ExecutionTimeMs)&lt;BR&gt;VALUES(@@SPID, 'clustered', 'one statement', DATEDIFF(ms, @dt, GETDATE()))&lt;/P&gt;
&lt;P&gt;EXEC DoBefore --Single allocations, heap:&lt;BR&gt;SET @dt = GETDATE()&lt;BR&gt;--BEGIN TRAN&lt;BR&gt;EXEC iHeapLoop @rows = @NumberOfRowsToInsert&lt;BR&gt;--COMMIT&lt;BR&gt;INSERT INTO TimeLogger (spid, TableStructure, InsertType, ExecutionTimeMs)&lt;BR&gt;VALUES(@@SPID, 'heap', 'loop', DATEDIFF(ms, @dt, GETDATE()))&lt;/P&gt;
&lt;P&gt;EXEC DoBefore --Single allocations, clustered&lt;BR&gt;SET @dt = GETDATE()&lt;BR&gt;--BEGIN TRAN&lt;BR&gt;EXEC iClusteredLoop @rows = @NumberOfRowsToInsert&lt;BR&gt;--COMMIT&lt;BR&gt;INSERT INTO TimeLogger (spid, TableStructure, InsertType, ExecutionTimeMs)&lt;BR&gt;VALUES(@@SPID, 'clustered', 'loop', DATEDIFF(ms, @dt, GETDATE()))&lt;BR&gt;GO&lt;/P&gt;
&lt;P&gt;--Run the tests&lt;BR&gt;EXEC CreateTables&lt;BR&gt;TRUNCATE TABLE TimeLogger&lt;BR&gt;TRUNCATE TABLE RowsToInsert INSERT INTO RowsToInsert VALUES(10000)&lt;/P&gt;
&lt;P&gt;--&amp;lt;Below can be executed over several connections&amp;gt;&lt;BR&gt;EXEC DoTheInserts&lt;BR&gt;EXEC DoTheInserts&lt;BR&gt;EXEC DoTheInserts&lt;BR&gt;EXEC DoTheInserts&lt;BR&gt;--&amp;lt;/Below can be executed over several connections&amp;gt;&lt;/P&gt;
&lt;P&gt;--How did we do?&lt;BR&gt;SELECT COUNT(*) AS NumberOfExecutions, TableStructure, InsertType, AVG(ExecutionTimeMs) AS AvgMs&lt;BR&gt;FROM TimeLogger WITH(NOLOCK)&lt;BR&gt;GROUP BY TableStructure, InsertType&lt;BR&gt;ORDER BY InsertType, TableStructure&lt;/P&gt;
&lt;P&gt;--Verify that no fragmentation&lt;BR&gt;SELECT &lt;BR&gt;&amp;nbsp;OBJECT_NAME(OBJECT_ID) AS objName&lt;BR&gt;,index_type_desc&lt;BR&gt;,avg_fragmentation_in_percent AS frag&lt;BR&gt;,page_count AS #pages&lt;BR&gt;,record_count&lt;BR&gt;FROM sys.dm_db_index_physical_stats(DB_ID(), NULL, NULL, NULL, 'DETAILED')&lt;BR&gt;WHERE OBJECT_NAME(OBJECT_ID) &amp;lt;&amp;gt; 'TimeLogger' AND index_level = 0&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BR&gt;&lt;div class = "shareblock"&gt;&lt;span class = "shareblockTitle"&gt;Share this post:&lt;/span&gt;&lt;span class = "shareblockLink"&gt; &lt;a href = "mailto:?subject=Are inserts quicker to heap or clustered tables?&amp;amp;body=Seen on SQLblog.com: %0A%0A%09Are inserts quicker to heap or clustered tables?%0A%0Ahttp://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/14/are-inserts-quicker-to-heap-or-clustered-tables.aspx" target="_blank" title = "Email Are inserts quicker to heap or clustered tables?"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/14/are-inserts-quicker-to-heap-or-clustered-tables.aspx&amp;amp;title=Are+inserts+quicker+to+heap+or+clustered+tables%3f" target="_blank" title = "Submit Are inserts quicker to heap or clustered tables? to del.icio.us"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/14/are-inserts-quicker-to-heap-or-clustered-tables.aspx&amp;amp;phase=2" target="_blank" title = "Submit Are inserts quicker to heap or clustered tables? to digg.com"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/14/are-inserts-quicker-to-heap-or-clustered-tables.aspx&amp;amp;title=Are+inserts+quicker+to+heap+or+clustered+tables%3f" target="_blank" title = "Submit Are inserts quicker to heap or clustered tables? to reddit.com"&gt;reddit!&lt;/a&gt; |  &lt;a href = "http://www.dotnetkicks.com/submit/?url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/14/are-inserts-quicker-to-heap-or-clustered-tables.aspx&amp;amp;title=Are+inserts+quicker+to+heap+or+clustered+tables%3f" target="_blank" title = "Submit Are inserts quicker to heap or clustered tables? to DotNetKicks"&gt;kick it!&lt;/a&gt; |  &lt;a href = "https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;mkt=en-us&amp;amp;url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/14/are-inserts-quicker-to-heap-or-clustered-tables.aspx&amp;amp;title=Are+inserts+quicker+to+heap+or+clustered+tables%3f&amp;amp;;top=1" target="_blank" title = "Add Are inserts quicker to heap or clustered tables? to Live Bookmarks"&gt;live it!&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;img src="http://info.sqlblog.com/a.aspx?ZoneID=0&amp;BannerID=12&amp;AdvertiserID=1&amp;CampaignID=12&amp;Task=Get&amp;Mode=TEXT&amp;SiteID=1&amp;RandomNumber=463323" width="1" height="1" border="0"&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=8372" width="1" height="1"&gt;</content><author><name>TiborKaraszi</name><uri>http://sqlblog.com/members/TiborKaraszi.aspx</uri></author><category term="Performance" scheme="http://sqlblog.com/blogs/tibor_karaszi/archive/tags/Performance/default.aspx" /><category term="indexes" scheme="http://sqlblog.com/blogs/tibor_karaszi/archive/tags/indexes/default.aspx" /></entry><entry><title>Code page backgrounder, courtesy of Erland Sommarskog</title><link rel="alternate" type="text/html" href="http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/09/code-page-backgrounder-courtesy-of-erland-sommarskog.aspx" /><id>http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/09/code-page-backgrounder-courtesy-of-erland-sommarskog.aspx</id><published>2008-08-09T12:49:00Z</published><updated>2008-08-09T12:49:00Z</updated><content type="html">&lt;P&gt;While browsing through the programming newsgroup today, I came across a post from Erland Sommarskog - a short backgrounder about code pages and collations. I've never seen code pages described so coherent and with so few words, so I asked Erland if I could quote his text in my blog (no, Erland doesn't blog :-) ). So below quoted text is with Erland's kind permission.&lt;/P&gt;
&lt;P&gt;For those of you who want to know more about Erland or read some of his great deep-dive articles, check out &lt;A href="http://www.sommarskog.se/"&gt;http://www.sommarskog.se/&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;"To start with, if we should be picky, there are no ASCII characters &amp;gt;= 128. &lt;BR&gt;There are however lot of other character sets that defines this area.&lt;/P&gt;
&lt;P&gt;Way back in the 80s vendors started to explore the area 128-255, and&lt;BR&gt;about each vendor come with its character set(s). The contribution&lt;BR&gt;from the IBM/Microsoft combo that ran MS-DOS was a number of code&lt;BR&gt;pages, of which 437 was of their oldest. Later, they realized that&lt;BR&gt;they did not support all languages in Western Europe, and they defined&lt;BR&gt;CP850 which served Western Europe better.&lt;/P&gt;
&lt;P&gt;Meanwhile, HP had Roman-8 and Digital had their DEC Multinational Character&lt;BR&gt;Set. Eventually, ISO settled on composing a standard, and they worked&lt;BR&gt;from DEC MCS - or DEC were smart to work from the ISO drafts, I don't know&lt;BR&gt;which. This resulted in ISO-8859 a family or originally eight 8-bit&lt;BR&gt;character sets, which recently evolved into 15 sets.&lt;/P&gt;
&lt;P&gt;By the time Microsoft divorced from IBM, they abandoned CP437 and&lt;BR&gt;CP850 as the character set for Windows, and went with ISO-8859, at&lt;BR&gt;least for Western Europe. Except that they added some printable&lt;BR&gt;characters in the range 128-159 where Latin-1 has only control characters.&lt;BR&gt;This became CodePage 1252, and CP1252 is the code page typically &lt;BR&gt;used for 8-bit Windows applications on a computer installed in Western&lt;BR&gt;Europe or the Americas. However, CP437/CP850 still lives on Windows&lt;BR&gt;today; the command-line windows uses a so-called OEM character set which&lt;BR&gt;is one of these.&lt;/P&gt;
&lt;P&gt;If you have a Windows program that uses CP1252, and the server collation&lt;BR&gt;is CP437, the client API will convert the data for you, so if you pass&lt;BR&gt;for instance Ö which has character code 216 in CP1252, the byte that &lt;BR&gt;gets stored in SQL Server will be another. When you retrieve data, &lt;BR&gt;data will be converted in the other direction. However, since CP1252&lt;BR&gt;and CP437 does not include the same characters, the conversion may&lt;BR&gt;not be roundtrip. For instance, Å may not be in CP437, so an Å from &lt;BR&gt;CP1252 will become A, and will remain A when you retrieve it.&lt;/P&gt;
&lt;P&gt;&amp;lt;TiborComment&amp;gt;Here I removed a section which was only relevant for the newsgroup thread in question&amp;lt;/TiborComment&amp;gt;&lt;/P&gt;
&lt;P&gt;Finally, all collations have 255 characters for varchar, and at least&lt;BR&gt;65535 characters for nvarchar."&lt;/P&gt;
&lt;P&gt;For those of you who want to dive deep in collations and such topics, check out &lt;A href="http://msdn.microsoft.com/en-us/library/bb330962.aspx"&gt;http://msdn.microsoft.com/en-us/library/bb330962.aspx&lt;/A&gt;.&lt;/P&gt;
&lt;BR&gt;&lt;div class = "shareblock"&gt;&lt;span class = "shareblockTitle"&gt;Share this post:&lt;/span&gt;&lt;span class = "shareblockLink"&gt; &lt;a href = "mailto:?subject=Code page backgrounder, courtesy of Erland Sommarskog&amp;amp;body=Seen on SQLblog.com: %0A%0A%09Code page backgrounder, courtesy of Erland Sommarskog%0A%0Ahttp://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/09/code-page-backgrounder-courtesy-of-erland-sommarskog.aspx" target="_blank" title = "Email Code page backgrounder, courtesy of Erland Sommarskog"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/09/code-page-backgrounder-courtesy-of-erland-sommarskog.aspx&amp;amp;title=Code+page+backgrounder%2c+courtesy+of+Erland+Sommarskog" target="_blank" title = "Submit Code page backgrounder, courtesy of Erland Sommarskog to del.icio.us"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/09/code-page-backgrounder-courtesy-of-erland-sommarskog.aspx&amp;amp;phase=2" target="_blank" title = "Submit Code page backgrounder, courtesy of Erland Sommarskog to digg.com"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/09/code-page-backgrounder-courtesy-of-erland-sommarskog.aspx&amp;amp;title=Code+page+backgrounder%2c+courtesy+of+Erland+Sommarskog" target="_blank" title = "Submit Code page backgrounder, courtesy of Erland Sommarskog to reddit.com"&gt;reddit!&lt;/a&gt; |  &lt;a href = "http://www.dotnetkicks.com/submit/?url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/09/code-page-backgrounder-courtesy-of-erland-sommarskog.aspx&amp;amp;title=Code+page+backgrounder%2c+courtesy+of+Erland+Sommarskog" target="_blank" title = "Submit Code page backgrounder, courtesy of Erland Sommarskog to DotNetKicks"&gt;kick it!&lt;/a&gt; |  &lt;a href = "https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;mkt=en-us&amp;amp;url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/09/code-page-backgrounder-courtesy-of-erland-sommarskog.aspx&amp;amp;title=Code+page+backgrounder%2c+courtesy+of+Erland+Sommarskog&amp;amp;;top=1" target="_blank" title = "Add Code page backgrounder, courtesy of Erland Sommarskog to Live Bookmarks"&gt;live it!&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;img src="http://info.sqlblog.com/a.aspx?ZoneID=0&amp;BannerID=12&amp;AdvertiserID=1&amp;CampaignID=12&amp;Task=Get&amp;Mode=TEXT&amp;SiteID=1&amp;RandomNumber=463323" width="1" height="1" border="0"&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=8310" width="1" height="1"&gt;</content><author><name>TiborKaraszi</name><uri>http://sqlblog.com/members/TiborKaraszi.aspx</uri></author><category term="Historical" scheme="http://sqlblog.com/blogs/tibor_karaszi/archive/tags/Historical/default.aspx" /><category term="International" scheme="http://sqlblog.com/blogs/tibor_karaszi/archive/tags/International/default.aspx" /></entry><entry><title>SQL Server 2008 and Visual Studio 2008</title><link rel="alternate" type="text/html" href="http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/08/sql-server-2008-and-visual-studio-2008.aspx" /><id>http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/08/sql-server-2008-and-visual-studio-2008.aspx</id><published>2008-08-08T15:24:00Z</published><updated>2008-08-08T15:24:00Z</updated><content type="html">&lt;P&gt;You probably already know that SQL Server 2008 RTM'd (yesterday). You need to be careful when installing SQL Server 2008 if you also have Visual Studio 2008 installed. It all has to do with the version of the framework that each product requires. Denis already blogged about it here: &lt;A href="http://sqlblog.com/blogs/denis_gobo/archive/2008/08/07/8261.aspx"&gt;http://sqlblog.com/blogs/denis_gobo/archive/2008/08/07/8261.aspx&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;I just found out that the SQL Server 2008 release notes has been updated with some extra information about this. Check it out at:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://download.microsoft.com/download/4/9/e/49eeb41a-a769-4520-80d6-671b8ae2bd06/SQLServer2008ReleaseNotes.htm"&gt;http://download.microsoft.com/download/4/9/e/49eeb41a-a769-4520-80d6-671b8ae2bd06/SQLServer2008ReleaseNotes.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Read the section below the "Before you install" title. It is worth the 3 minutes it take to read it!!!&lt;/P&gt;
&lt;BR&gt;&lt;div class = "shareblock"&gt;&lt;span class = "shareblockTitle"&gt;Share this post:&lt;/span&gt;&lt;span class = "shareblockLink"&gt; &lt;a href = "mailto:?subject=SQL Server 2008 and Visual Studio 2008&amp;amp;body=Seen on SQLblog.com: %0A%0A%09SQL Server 2008 and Visual Studio 2008%0A%0Ahttp://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/08/sql-server-2008-and-visual-studio-2008.aspx" target="_blank" title = "Email SQL Server 2008 and Visual Studio 2008"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/08/sql-server-2008-and-visual-studio-2008.aspx&amp;amp;title=SQL+Server+2008+and+Visual+Studio+2008" target="_blank" title = "Submit SQL Server 2008 and Visual Studio 2008 to del.icio.us"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/08/sql-server-2008-and-visual-studio-2008.aspx&amp;amp;phase=2" target="_blank" title = "Submit SQL Server 2008 and Visual Studio 2008 to digg.com"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/08/sql-server-2008-and-visual-studio-2008.aspx&amp;amp;title=SQL+Server+2008+and+Visual+Studio+2008" target="_blank" title = "Submit SQL Server 2008 and Visual Studio 2008 to reddit.com"&gt;reddit!&lt;/a&gt; |  &lt;a href = "http://www.dotnetkicks.com/submit/?url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/08/sql-server-2008-and-visual-studio-2008.aspx&amp;amp;title=SQL+Server+2008+and+Visual+Studio+2008" target="_blank" title = "Submit SQL Server 2008 and Visual Studio 2008 to DotNetKicks"&gt;kick it!&lt;/a&gt; |  &lt;a href = "https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;mkt=en-us&amp;amp;url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/08/sql-server-2008-and-visual-studio-2008.aspx&amp;amp;title=SQL+Server+2008+and+Visual+Studio+2008&amp;amp;;top=1" target="_blank" title = "Add SQL Server 2008 and Visual Studio 2008 to Live Bookmarks"&gt;live it!&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;img src="http://info.sqlblog.com/a.aspx?ZoneID=0&amp;BannerID=12&amp;AdvertiserID=1&amp;CampaignID=12&amp;Task=Get&amp;Mode=TEXT&amp;SiteID=1&amp;RandomNumber=463323" width="1" height="1" border="0"&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=8287" width="1" height="1"&gt;</content><author><name>TiborKaraszi</name><uri>http://sqlblog.com/members/TiborKaraszi.aspx</uri></author><category term="Installation" scheme="http://sqlblog.com/blogs/tibor_karaszi/archive/tags/Installation/default.aspx" /></entry><entry><title>Analogy between SQL Server and operating systems</title><link rel="alternate" type="text/html" href="http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/08/analogy-between-sql-server-and-operating-systems.aspx" /><id>http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/08/analogy-between-sql-server-and-operating-systems.aspx</id><published>2008-08-08T08:25:00Z</published><updated>2008-08-08T08:25:00Z</updated><content type="html">&lt;P&gt;With SQL Server 2008 released, I was thinking back of earlier versions of SQL Server. And I decided to compare them to the MS operating systems. Not a point-in-time comparsion, like "SQL Server version x was released year a, which was the same year that OS y was released.". I'm thinking more of the feel you have for the product. Why would anyone want to do that? I don't know - for fun, perhaps? While writing below I realized that the comparsions/analogies worked better the older the product is. Perhaps a product need to be obsolete for us to have the sentimental feeling required for this type of comparsion? Anyhow,&amp;nbsp;here goes:&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;SQL Server 1.x &amp;lt;-&amp;gt; DOS&lt;/STRONG&gt;&lt;BR&gt;(I do know it ran on OS/2, but again this is more about how you feel for the product.)&lt;BR&gt;I know, perhaps not all fair, but think about it. We are talking about command-line environments, or at the best some full-screen character based applications (like edit.exe or saf.exe). And installation was floppy based where the product did fit on a couple of floppies.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;SQL Server 4.x &amp;lt;-&amp;gt; OS/2 or Windows pre-95&lt;/STRONG&gt;&lt;BR&gt;I can't decide here. &lt;BR&gt;OS/2 had the merit that it wasn't a bad OS, but almost no apps were developed for it (think back to version 1.2 and 1.3 and what it was at the time - and what it could have been), and it wasn't a fun environment to work in. Windows pre-95 had the merit of being a GUI which, sort of, brought multitasking to the desktop - but what about robustness? &lt;BR&gt;Same goes for SQL server 4.x. It was revolutionary in some sense, like: Imagine fitting a real RDBMS in a PC? Now smaller businesses can start using "real" RDBMSs. But OTOH, it was very unpolished. Remember the GUI tools? They were really Windows apps&amp;nbsp;where some conversion tool converted them for OS/2. &lt;BR&gt;So, I think it is a draw between OS/2 and Windows pre-95.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;SQL Server 6.x &amp;lt;-&amp;gt; Windows NT 3.x or Windows 9x&lt;/STRONG&gt;&lt;BR&gt;Again, I can't decide.&lt;BR&gt;In one way, SQL Server 6.x was MS first "own" release. But OTOH, the Sybase code base was still there. MS mainly did tool stuff, along with some engine stuff (like ANSI SQL compliance). But it wasn't a re-write of the engine. &lt;BR&gt;This can compare to Windows 9x - the DOS heritage was still there, in some sense.&lt;BR&gt;If you compare SQL Server 6.x to Windows NT 3.x you can also see similarities. NT 3.x was the first versions of the new revolutionary OS from MS. But it still looked like ... old Windows - something you might compare with SQL Server 6.x enterprise Manager.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;SQL Server&amp;nbsp;7.0 &amp;lt;-&amp;gt; NT 4&lt;BR&gt;&lt;/STRONG&gt;I was originally going to put Windows 2000 here, but after thinking a while, I decide for NT 4.&lt;BR&gt;7.0 was the first version of the new architecture. A lot happened, where the engine was all re-written. New stuff was introduced (Profiler, DTS, Olap server). So, at the engine level, we basically got a more modern look-and-feel. &lt;BR&gt;To some extent NT 4 was similar. You got a new GUI (adopted from Windows 9x). The revolution was that you now had an *stable* OS which you also could run as your desktop OS. I bet that many of you (computer nerds)/readers preferred NT 4 instead of Windows 9x at that time. I did. There were some architectural news in the OS as well, like the device driver model (some stuff were moved to kernel mode - if my memory serves me).&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;SQL Server 2000 &amp;lt;-&amp;gt; Windows 2000&lt;BR&gt;&lt;/STRONG&gt;Seems too easy, but think about it.&lt;BR&gt;SQL Server 2000 was when the new architecture matured. IMO, a great release at that time. OK, some would argue that it didn't happened that much between 7.0 and 2000, but maturing and polish of the new architecture is a major thing to me.&lt;BR&gt;Windows 2000 can also be seen as becoming mature - ready to be used in masses. OK, there were some revolutionary new stuff like AD, but you can't expect the analogy to fit 100%. ;-)&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;SQL Server 2005 &amp;lt;-&amp;gt; Vista&lt;/STRONG&gt;&lt;BR&gt;Hmm, is my analogy breaking down here?&lt;BR&gt;I was originally going to put Windows 2003 here. But that was a bit too much going chronologically hand-in-hand. &lt;BR&gt;And I think that XP is a bit unfair (perhaps XP would be a better fit for SQL Server 2000?). &lt;BR&gt;But 2005 did have lots and lots of changes and new features. And so did Vista. Vista has a rather slow adaption rate, and I have the same feeling for SQL Server 2005. Many people seems to wait for Vista+, a perhaps more cleaned-up OS? And some seem to be waiting for SQL Server 2008, even though perhaps not for the same reasons.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;SQL Server 2008 &amp;lt;-&amp;gt; Vista +&lt;/STRONG&gt;&lt;BR&gt;This&amp;nbsp;was unavoidable, considering how we got here. I won't dwell into this, since it is too&amp;nbsp;early to say how we feel about these releases in 10 years from now...&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now why on earth did I write this post? Well, I have been doing some 6 full installations and some 12 database engine installations of SQL Server 2008 the last two days - so I've had a lot of time on my hands. :-)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BR&gt;&lt;div class = "shareblock"&gt;&lt;span class = "shareblockTitle"&gt;Share this post:&lt;/span&gt;&lt;span class = "shareblockLink"&gt; &lt;a href = "mailto:?subject=Analogy between SQL Server and operating systems&amp;amp;body=Seen on SQLblog.com: %0A%0A%09Analogy between SQL Server and operating systems%0A%0Ahttp://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/08/analogy-between-sql-server-and-operating-systems.aspx" target="_blank" title = "Email Analogy between SQL Server and operating systems"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/08/analogy-between-sql-server-and-operating-systems.aspx&amp;amp;title=Analogy+between+SQL+Server+and+operating+systems" target="_blank" title = "Submit Analogy between SQL Server and operating systems to del.icio.us"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/08/analogy-between-sql-server-and-operating-systems.aspx&amp;amp;phase=2" target="_blank" title = "Submit Analogy between SQL Server and operating systems to digg.com"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/08/analogy-between-sql-server-and-operating-systems.aspx&amp;amp;title=Analogy+between+SQL+Server+and+operating+systems" target="_blank" title = "Submit Analogy between SQL Server and operating systems to reddit.com"&gt;reddit!&lt;/a&gt; |  &lt;a href = "http://www.dotnetkicks.com/submit/?url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/08/analogy-between-sql-server-and-operating-systems.aspx&amp;amp;title=Analogy+between+SQL+Server+and+operating+systems" target="_blank" title = "Submit Analogy between SQL Server and operating systems to DotNetKicks"&gt;kick it!&lt;/a&gt; |  &lt;a href = "https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;mkt=en-us&amp;amp;url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/08/08/analogy-between-sql-server-and-operating-systems.aspx&amp;amp;title=Analogy+between+SQL+Server+and+operating+systems&amp;amp;;top=1" target="_blank" title = "Add Analogy between SQL Server and operating systems to Live Bookmarks"&gt;live it!&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;img src="http://info.sqlblog.com/a.aspx?ZoneID=0&amp;BannerID=12&amp;AdvertiserID=1&amp;CampaignID=12&amp;Task=Get&amp;Mode=TEXT&amp;SiteID=1&amp;RandomNumber=463323" width="1" height="1" border="0"&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=8277" width="1" height="1"&gt;</content><author><name>TiborKaraszi</name><uri>http://sqlblog.com/members/TiborKaraszi.aspx</uri></author><category term="General" scheme="http://sqlblog.com/blogs/tibor_karaszi/archive/tags/General/default.aspx" /><category term="Historical" scheme="http://sqlblog.com/blogs/tibor_karaszi/archive/tags/Historical/default.aspx" /></entry><entry><title>Personal backups</title><link rel="alternate" type="text/html" href="http://sqlblog.com/blogs/tibor_karaszi/archive/2008/07/28/personal-backups.aspx" /><id>http://sqlblog.com/blogs/tibor_karaszi/archive/2008/07/28/personal-backups.aspx</id><published>2008-07-28T10:52:00Z</published><updated>2008-07-28T10:52:00Z</updated><content type="html">&lt;P&gt;I finally got to spend some time on how to backup my machines,&amp;nbsp;my home machines and laptop. This was triggered from when I got back from a week in Egypt and&amp;nbsp;my LaCie NAS wouldn't start. I finally did manage to get it started by connecting through USB and whacking it with a hammer. However this triggered something I've been thinking about for a while - to buy a backup disk (NAS) with RAID 1 and implement a "proper" backup stragegy. &lt;/P&gt;
&lt;P&gt;I decided for QNAP TS-209&amp;nbsp;Pro II which is Linux based. This device supports loads of stuff (DLNA, FTP, web server, DDNS, printers, mySQL etc), but I will at least initially only use the file server bit (Samba). I do not want a fullblown PC for this, since I want something simple, which is running all the time with low energy usage, doesn't produce too much heat, doesn't expect a monitor etc. So, a NAS seems just about the right thing for me. This unit was also simple to install and setup. Here's a simplification of my environment:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;My "main" machine is my desktop machine.&lt;/LI&gt;
&lt;LI&gt;I also have a laptop, which is what I'm using when I'm at customer sites and when I do training.&lt;/LI&gt;
&lt;LI&gt;I have an USB drive mainly used on above laptop.&lt;/LI&gt;
&lt;LI&gt;And of course the NAS.&lt;/LI&gt;
&lt;LI&gt;There are other machines as well (including USB disks), but I won't discuss them here since they don't change the basic principles.&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;I've already a long time ago decided on the concept of ownership. I.e., some folder is owned by some particular machine. &lt;/P&gt;
&lt;P&gt;Some 3-4 years ago, I had a disk crash which made me lose 2 weeks worth of email. I decided that I cannot rely on manually copying folders around. Perhaps my most important folder is a "document" folder (where I among other things have the outlook PST file) on my desktop machine. I wrote a .NET console program which reads some config info from a local SQL Server and then creates a folder with current date as name and copies the content of my "document" folder to this new folder. After this is done, it removes every folder older than 1 week - except for folders created on day 1 in the month.&amp;nbsp;I put this in the startup group. This has served me well for this "document" folder - mainly because it is small in size (some 200 MB). But over time, things has become a bit more complicated. A few examples:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;I have a "courseFiles" folder on my laptop and this should be owned by the laptop. I might for instance do some modification for a demo-file when I'm doing training.&lt;/LI&gt;
&lt;LI&gt;I have over time realized that some stuff are too large to have in the "documents" folder, like SQL Server videos I've produced. &lt;/LI&gt;
&lt;LI&gt;I have virtual machines. I can't have them copied every time I start my machine including many many generations of them.&lt;/LI&gt;
&lt;LI&gt;I have ghost images which includes virtual machines. Same applies as above.&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;So it was time to expand on my simple "documents" backup solution. I have some very important aspects:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;I can reinstall OS and applications. I already have a small script which produces a file with what apps are installed (autostarted) so I know what to reinstall if I have to whack a machine. So, no backup of binary files.&lt;/LI&gt;
&lt;LI&gt;I don't want to virtualize everyting. I don't feel like paying the penalty for it. I'm too pedantic, so I know I can spend days just to get this little thing working in virtual environment - and I don't have that time. Also, I don't see how virtualization will change anything. I will still have "productivity OS's" where I have important files which I need to backup.&lt;/LI&gt;
&lt;LI&gt;A backup need work with&amp;nbsp;pure files, same folder structure as source. I.e., I don't want to rely on some backup app whenever I need to restore. Nor do I want some "diff" strategy only to realize that my base is corrupted.&lt;/LI&gt;
&lt;LI&gt;A folder has an ownership. This is the machine which owns the folder. For instance, the "documents" folder is owned by my desktop machine - any changes done in that folder on my laptop should be discarded and dissapear.&lt;/LI&gt;
&lt;LI&gt;The NAS is the backup station. This is where all backups go. Some folders I also want on some other machine ("documents" on laptop, "courseFiles" on desktop) but such s folder should be treated as read-only.&lt;/LI&gt;
&lt;LI&gt;I want my backup files distributed and independent of each other. I.e., I do NOT want a distributed system which fails if one machine is lost (think RAID0). What I DO want is a distributed system which can surive several failures - like house burning down and several machines lost (think distributed RAID 1 with several mirrors). Now, don't mistake my RAID analogy for some real-time replication solution - since I want to be able to find an older versone of a file on some backup machine if I happen to destroy the owning file.&lt;/LI&gt;
&lt;LI&gt;Having only one machine (laptop) is not an option for me. &lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;I found a backup program which suit my needs: SyncBack from&amp;nbsp;&lt;A href="http://www.2brightsparks.com/"&gt;http://www.2brightsparks.com/&lt;/A&gt;. This has a lot of features and functionality, and it allow the level of customization that I need. Here's how I have created my backup definitions (one per folder):&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;I have three root folders on my NAS "backup" share. One per source (desktop, laptop and laptop USB disk).&lt;/LI&gt;
&lt;LI&gt;For each folder, I create a backup job on each owning machine, per folder that the machine owns. &lt;/LI&gt;
&lt;LI&gt;For some folders, I also create a "downstream" backup. Say for instance the "courseFiles" folder. This is owned by the laptop, but I want to have a copy available on my desktop machine as well. Of&amp;nbsp;course I have an "upstream" backup definition&amp;nbsp;from my laptop to the NAS. But I also have a "downstream" job from the NAS to the desktop machine.&lt;/LI&gt;
&lt;LI&gt;All backup definitions are defined as source always win (not newest file), and delete file if exist on target but not source. This is important since it implements pure one-way "replication". &lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;It took me a couple of hours to learn the backup app and setup the jobs.&amp;nbsp; (It took even longer time to do the initial copying of folders to my NAS (something I did before setting up the backup jobs) - but this was only because sheer volume.) But thaks to SyncBack (complemented with my own small applet for generation type backups) I now have a backup solution which is easy to understand and hopefully can survive multiple failures.&lt;BR&gt;&lt;/P&gt;
&lt;BR&gt;&lt;div class = "shareblock"&gt;&lt;span class = "shareblockTitle"&gt;Share this post:&lt;/span&gt;&lt;span class = "shareblockLink"&gt; &lt;a href = "mailto:?subject=Personal backups&amp;amp;body=Seen on SQLblog.com: %0A%0A%09Personal backups%0A%0Ahttp://sqlblog.com/blogs/tibor_karaszi/archive/2008/07/28/personal-backups.aspx" target="_blank" title = "Email Personal backups"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/07/28/personal-backups.aspx&amp;amp;title=Personal+backups" target="_blank" title = "Submit Personal backups to del.icio.us"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/07/28/personal-backups.aspx&amp;amp;phase=2" target="_blank" title = "Submit Personal backups to digg.com"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/07/28/personal-backups.aspx&amp;amp;title=Personal+backups" target="_blank" title = "Submit Personal backups to reddit.com"&gt;reddit!&lt;/a&gt; |  &lt;a href = "http://www.dotnetkicks.com/submit/?url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/07/28/personal-backups.aspx&amp;amp;title=Personal+backups" target="_blank" title = "Submit Personal backups to DotNetKicks"&gt;kick it!&lt;/a&gt; |  &lt;a href = "https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;mkt=en-us&amp;amp;url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/07/28/personal-backups.aspx&amp;amp;title=Personal+backups&amp;amp;;top=1" target="_blank" title = "Add Personal backups to Live Bookmarks"&gt;live it!&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;img src="http://info.sqlblog.com/a.aspx?ZoneID=0&amp;BannerID=12&amp;AdvertiserID=1&amp;CampaignID=12&amp;Task=Get&amp;Mode=TEXT&amp;SiteID=1&amp;RandomNumber=463323" width="1" height="1" border="0"&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=8068" width="1" height="1"&gt;</content><author><name>TiborKaraszi</name><uri>http://sqlblog.com/members/TiborKaraszi.aspx</uri></author><category term="Backup" scheme="http://sqlblog.com/blogs/tibor_karaszi/archive/tags/Backup/default.aspx" /></entry><entry><title>Yet some more fixes for sp_indexinfo...</title><link rel="alternate" type="text/html" href="http://sqlblog.com/blogs/tibor_karaszi/archive/2008/07/09/yet-some-more-fixes-for-sp-indexinfo.aspx" /><id>http://sqlblog.com/blogs/tibor_karaszi/archive/2008/07/09/yet-some-more-fixes-for-sp-indexinfo.aspx</id><published>2008-07-09T08:03:00Z</published><updated>2008-07-09T08:03:00Z</updated><content type="html">&lt;P&gt;I got some more feedback (see yesterday's blog post on this) which I now incorporated into sp_indexinfo. See change log at bottom of the article for details.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://www.karaszi.com/SQLServer/util_sp_indexinfo.asp"&gt;http://www.karaszi.com/SQLServer/util_sp_indexinfo.asp&lt;/A&gt;&lt;/P&gt;
&lt;BR&gt;&lt;div class = "shareblock"&gt;&lt;span class = "shareblockTitle"&gt;Share this post:&lt;/span&gt;&lt;span class = "shareblockLink"&gt; &lt;a href = "mailto:?subject=Yet some more fixes for sp_indexinfo...&amp;amp;body=Seen on SQLblog.com: %0A%0A%09Yet some more fixes for sp_indexinfo...%0A%0Ahttp://sqlblog.com/blogs/tibor_karaszi/archive/2008/07/09/yet-some-more-fixes-for-sp-indexinfo.aspx" target="_blank" title = "Email Yet some more fixes for sp_indexinfo..."&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/07/09/yet-some-more-fixes-for-sp-indexinfo.aspx&amp;amp;title=Yet+some+more+fixes+for+sp_indexinfo..." target="_blank" title = "Submit Yet some more fixes for sp_indexinfo... to del.icio.us"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/07/09/yet-some-more-fixes-for-sp-indexinfo.aspx&amp;amp;phase=2" target="_blank" title = "Submit Yet some more fixes for sp_indexinfo... to digg.com"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/07/09/yet-some-more-fixes-for-sp-indexinfo.aspx&amp;amp;title=Yet+some+more+fixes+for+sp_indexinfo..." target="_blank" title = "Submit Yet some more fixes for sp_indexinfo... to reddit.com"&gt;reddit!&lt;/a&gt; |  &lt;a href = "http://www.dotnetkicks.com/submit/?url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/07/09/yet-some-more-fixes-for-sp-indexinfo.aspx&amp;amp;title=Yet+some+more+fixes+for+sp_indexinfo..." target="_blank" title = "Submit Yet some more fixes for sp_indexinfo... to DotNetKicks"&gt;kick it!&lt;/a&gt; |  &lt;a href = "https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;mkt=en-us&amp;amp;url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/07/09/yet-some-more-fixes-for-sp-indexinfo.aspx&amp;amp;title=Yet+some+more+fixes+for+sp_indexinfo...&amp;amp;;top=1" target="_blank" title = "Add Yet some more fixes for sp_indexinfo... to Live Bookmarks"&gt;live it!&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;img src="http://info.sqlblog.com/a.aspx?ZoneID=0&amp;BannerID=12&amp;AdvertiserID=1&amp;CampaignID=12&amp;Task=Get&amp;Mode=TEXT&amp;SiteID=1&amp;RandomNumber=463323" width="1" height="1" border="0"&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=7739" width="1" height="1"&gt;</content><author><name>TiborKaraszi</name><uri>http://sqlblog.com/members/TiborKaraszi.aspx</uri></author><category term="Performance" scheme="http://sqlblog.com/blogs/tibor_karaszi/archive/tags/Performance/default.aspx" /><category term="indexes" scheme="http://sqlblog.com/blogs/tibor_karaszi/archive/tags/indexes/default.aspx" /></entry><entry><title>New version of sp_indexinfo</title><link rel="alternate" type="text/html" href="http://sqlblog.com/blogs/tibor_karaszi/archive/2008/07/08/new-version-of-sp-indexinfo.aspx" /><id>http://sqlblog.com/blogs/tibor_karaszi/archive/2008/07/08/new-version-of-sp-indexinfo.aspx</id><published>2008-07-08T07:58:00Z</published><updated>2008-07-08T07:58:00Z</updated><content type="html">&lt;P&gt;(See my &lt;A class="" title="initial blog post" href="http://sqlblog.com/blogs/tibor_karaszi/archive/2008/07/07/fed-up-with-hunting-physical-index-details.aspx"&gt;initial blog post&lt;/A&gt; for&amp;nbsp;general information about this proc.)&lt;/P&gt;
&lt;P&gt;I just updated sp_indexinfo a bit:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;I added the schema name as a new column in the output of the first resultset.&lt;/LI&gt;
&lt;LI&gt;I added an optional second resultset with missing index information. This information is obviously&amp;nbsp;drawn from the missing index dynamic management views. I'm not sure I generated the CREATE INDEX statment properly (the equality and inequality columns) since I didn't have much missing index entries to play with at the moment. All tests and replies are much welcome ("work fine" - "doesn't work" - "doesn't work because of..." - "change aaa to bbb" etc.).&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;I also updated the web site with some tips on creating a view in the databases where &lt;STRONG&gt;you want to work a lot&lt;/STRONG&gt; so you can select from this view, aggregate etc. I will try to as much as possible stick with less procedural code and more set-based code. My aim is to have perhaps only two SELECT statements in the proc, so we can just take a SELECT statement, create a view or function inside your database and work with it from there. So, for instance, I will probably not add support for specify 'schemaname.tablename' for the first parameter as that will probably require some procedural parsing code (as seen in sp_helpindex). There's a trade-off between all the nice things you can complement using procedural code and having all in one or a few SELECT statments and being able to simply creating a view or table function from those. &lt;/P&gt;
&lt;P&gt;One possible enhancement is to add fragmentation information. For this I will need to perform some type of join or subquery against sys.dm_db_index_physical_stats. My concern here is the cases where you &lt;STRONG&gt;don't&lt;/STRONG&gt; want this information (because&amp;nbsp;of cost for large tables/databases). Ideally I don't want two versions of the query (see above paragraph) but I also don't want to pay the penalty in cases where we don't want this info. Possibly this is doable using some correlated subquery as a column together with CASE, but this is only in my mind yet. Suggestions and thoughts are welcome.&lt;/P&gt;
&lt;P&gt;You find the proc at: &lt;A href="http://www.karaszi.com/SQLServer/util_sp_indexinfo.asp"&gt;http://www.karaszi.com/SQLServer/util_sp_indexinfo.asp&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;BR&gt;&lt;div class = "shareblock"&gt;&lt;span class = "shareblockTitle"&gt;Share this post:&lt;/span&gt;&lt;span class = "shareblockLink"&gt; &lt;a href = "mailto:?subject=New version of sp_indexinfo&amp;amp;body=Seen on SQLblog.com: %0A%0A%09New version of sp_indexinfo%0A%0Ahttp://sqlblog.com/blogs/tibor_karaszi/archive/2008/07/08/new-version-of-sp-indexinfo.aspx" target="_blank" title = "Email New version of sp_indexinfo"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/07/08/new-version-of-sp-indexinfo.aspx&amp;amp;title=New+version+of+sp_indexinfo" target="_blank" title = "Submit New version of sp_indexinfo to del.icio.us"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/07/08/new-version-of-sp-indexinfo.aspx&amp;amp;phase=2" target="_blank" title = "Submit New version of sp_indexinfo to digg.com"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/07/08/new-version-of-sp-indexinfo.aspx&amp;amp;title=New+version+of+sp_indexinfo" target="_blank" title = "Submit New version of sp_indexinfo to reddit.com"&gt;reddit!&lt;/a&gt; |  &lt;a href = "http://www.dotnetkicks.com/submit/?url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/07/08/new-version-of-sp-indexinfo.aspx&amp;amp;title=New+version+of+sp_indexinfo" target="_blank" title = "Submit New version of sp_indexinfo to DotNetKicks"&gt;kick it!&lt;/a&gt; |  &lt;a href = "https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;mkt=en-us&amp;amp;url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/07/08/new-version-of-sp-indexinfo.aspx&amp;amp;title=New+version+of+sp_indexinfo&amp;amp;;top=1" target="_blank" title = "Add New version of sp_indexinfo to Live Bookmarks"&gt;live it!&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;img src="http://info.sqlblog.com/a.aspx?ZoneID=0&amp;BannerID=12&amp;AdvertiserID=1&amp;CampaignID=12&amp;Task=Get&amp;Mode=TEXT&amp;SiteID=1&amp;RandomNumber=463323" width="1" height="1" border="0"&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=7715" width="1" height="1"&gt;</content><author><name>TiborKaraszi</name><uri>http://sqlblog.com/members/TiborKaraszi.aspx</uri></author><category term="Performance" scheme="http://sqlblog.com/blogs/tibor_karaszi/archive/tags/Performance/default.aspx" /><category term="indexes" scheme="http://sqlblog.com/blogs/tibor_karaszi/archive/tags/indexes/default.aspx" /></entry><entry><title>Fed up with hunting physical index details?</title><link rel="alternate" type="text/html" href="http://sqlblog.com/blogs/tibor_karaszi/archive/2008/07/07/fed-up-with-hunting-physical-index-details.aspx" /><id>http://sqlblog.com/blogs/tibor_karaszi/archive/2008/07/07/fed-up-with-hunting-physical-index-details.aspx</id><published>2008-07-07T12:17:00Z</published><updated>2008-07-07T12:17:00Z</updated><content type="html">&lt;P&gt;I am. I find myself endlessly hunting for index information when working against the various SQL Servers I come in contact with. And, sure, the information is there. You just need to go and get it. This generally means that I start with sp_helpindex. Then some SELECT from sys.indexes. Then some more against sys.partitions and sys.allocation units (we want space usage stats as well). And perhaps general usage stats (sys.dm_index_usage_stats). (I sometimes might even use the GUI (SSMS) reports and index dialog - but you might already know that I'm not much of a GUI person.)&lt;/P&gt;
&lt;P&gt;The good news with all this is that I learn to use these catalog and dynamic management views. Bad news is that it is kind of ... boring to do the same thing again and again. &lt;/P&gt;
&lt;P&gt;This is why wrote sp_indexinfo. You might have your own index information procedures (which you wrote yourself or found on the Internet). If not, you are welcome to use this one. I aim to improve it over time, so suggestions are welcome. Possible improvements include:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Make it a function. Functions are nice since we can order the results, aggregate, and basically do whatever we want to when we SELECT from the function. But for this I need to find out how we install a user-defined global system function - there's no supported way to do this. I'm not sure I want to go there...&lt;/LI&gt;
&lt;LI&gt;Reurn missing index information as well. For this we probably want two resultsets, and only return missing index information when we targeted *one* table (no wildcards). If we do this, then function is out since a function can only return *one* result set.&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;If you care to give it a spin, please let me know. I just wrote the procedure, so I haven't tested it much yet. If you do find bugs, please leave a comment and I will incorporate into the source (let me know if you want to be acknowledged). Any comments are welcome.&lt;/P&gt;
&lt;P&gt;You find the proc at: &lt;A href="http://www.karaszi.com/SQLServer/util_sp_indexinfo.asp"&gt;http://www.karaszi.com/SQLServer/util_sp_indexinfo.asp&lt;/A&gt;&lt;/P&gt;
&lt;BR&gt;&lt;div class = "shareblock"&gt;&lt;span class = "shareblockTitle"&gt;Share this post:&lt;/span&gt;&lt;span class = "shareblockLink"&gt; &lt;a href = "mailto:?subject=Fed up with hunting physical index details?&amp;amp;body=Seen on SQLblog.com: %0A%0A%09Fed up with hunting physical index details?%0A%0Ahttp://sqlblog.com/blogs/tibor_karaszi/archive/2008/07/07/fed-up-with-hunting-physical-index-details.aspx" target="_blank" title = "Email Fed up with hunting physical index details?"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/07/07/fed-up-with-hunting-physical-index-details.aspx&amp;amp;title=Fed+up+with+hunting+physical+index+details%3f" target="_blank" title = "Submit Fed up with hunting physical index details? to del.icio.us"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/07/07/fed-up-with-hunting-physical-index-details.aspx&amp;amp;phase=2" target="_blank" title = "Submit Fed up with hunting physical index details? to digg.com"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/07/07/fed-up-with-hunting-physical-index-details.aspx&amp;amp;title=Fed+up+with+hunting+physical+index+details%3f" target="_blank" title = "Submit Fed up with hunting physical index details? to reddit.com"&gt;reddit!&lt;/a&gt; |  &lt;a href = "http://www.dotnetkicks.com/submit/?url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/07/07/fed-up-with-hunting-physical-index-details.aspx&amp;amp;title=Fed+up+with+hunting+physical+index+details%3f" target="_blank" title = "Submit Fed up with hunting physical index details? to DotNetKicks"&gt;kick it!&lt;/a&gt; |  &lt;a href = "https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;mkt=en-us&amp;amp;url=http://sqlblog.com/blogs/tibor_karaszi/archive/2008/07/07/fed-up-with-hunting-physical-index-details.aspx&amp;amp;title=Fed+up+with+hunting+physical+index+details%3f&amp;amp;;top=1" target="_blank" title = "Add Fed up with hunting physical index details? to Live Bookmarks"&gt;live it!&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;img src="http://info.sqlblog.com/a.aspx?ZoneID=0&amp;BannerID=12&amp;AdvertiserID=1&amp;CampaignID=12&amp;Task=Get&amp;Mode=TEXT&amp;SiteID=1&amp;RandomNumber=463323" width="1" height="1" border="0"&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=7687" width="1" height="1"&gt;</content><author><name>TiborKaraszi</name><uri>http://sqlblog.com/members/TiborKaraszi.aspx</uri></author><category term="Performance" scheme="http://sqlblog.com/blogs/tibor_karaszi/archive/tags/Performance/default.aspx" /><category term="indexes" scheme="http://sqlblog.com/blogs/tibor_karaszi/archive/tags/indexes/default.aspx" /></entry></feed>