<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/" version="2.0">
    <channel>
        <title>Ramblings of a DBA</title>
        <link>http://weblogs.sqlteam.com/tarad/Default.aspx</link>
        <description>Tara Kizer</description>
        <language>en-US</language>
        <copyright>Tara Kizer</copyright>
        <managingEditor>tara.kizer@gmail.com</managingEditor>
        <generator>Subtext Version 1.9.4.0</generator>
        <image>
            <title>Ramblings of a DBA</title>
            <url>http://weblogs.sqlteam.com/images/RSS2Image.gif</url>
            <link>http://weblogs.sqlteam.com/tarad/Default.aspx</link>
            <width>77</width>
            <height>60</height>
        </image>
        <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/RamblingsOfADba" type="application/rss+xml" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><item>
            <title>Multiple &amp;ldquo;clustered&amp;rdquo; indexes on a SQL Server table</title>
            <link>http://weblogs.sqlteam.com/tarad/archive/2009/11/09/Multiple-ldquoclusteredrdquo-indexes-on-a-SQL-Server-table.aspx</link>
            <description>&lt;p&gt;You can only have one clustered index on each SQL Server table, however there are two ways to create pseudo clustered indexes on a table:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Create clustered indexed on a view (indexed view) that covers the table &lt;/li&gt;    &lt;li&gt;Create covering index on the entire table&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;Let's look at the following table:&lt;/p&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;CREATE&lt;/span&gt; &lt;span class="kwrd"&gt;TABLE&lt;/span&gt; t1 
(
    c1 &lt;span class="kwrd"&gt;int&lt;/span&gt;, 
    c2 &lt;span class="kwrd"&gt;varchar&lt;/span&gt;(5), 
    c3 bigint, 
    c4 datetime, 
    &lt;span class="kwrd"&gt;CONSTRAINT&lt;/span&gt; PK_t1 &lt;span class="kwrd"&gt;PRIMARY&lt;/span&gt; &lt;span class="kwrd"&gt;KEY&lt;/span&gt; &lt;span class="kwrd"&gt;CLUSTERED&lt;/span&gt; (c1, c2, c3, c4)
)
GO&lt;/pre&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;p&gt;For option 1 above, here's the indexed view and clustered index:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;SET&lt;/span&gt; NUMERIC_ROUNDABORT &lt;span class="kwrd"&gt;OFF&lt;/span&gt;;
&lt;span class="kwrd"&gt;SET&lt;/span&gt; ANSI_PADDING, ANSI_WARNINGS, CONCAT_NULL_YIELDS_NULL, ARITHABORT,
    QUOTED_IDENTIFIER, ANSI_NULLS &lt;span class="kwrd"&gt;ON&lt;/span&gt;;
&lt;span class="kwrd"&gt;GO&lt;/span&gt;
&lt;span class="kwrd"&gt;CREATE&lt;/span&gt; &lt;span class="kwrd"&gt;VIEW&lt;/span&gt; v1 &lt;span class="kwrd"&gt;WITH&lt;/span&gt; SCHEMABINDING
&lt;span class="kwrd"&gt;AS&lt;/span&gt; 
&lt;span class="kwrd"&gt;SELECT&lt;/span&gt; c1, c2, c3, c4 &lt;span class="kwrd"&gt;FROM&lt;/span&gt; dbo.t1
&lt;span class="kwrd"&gt;GO&lt;/span&gt;
&lt;span class="kwrd"&gt;CREATE&lt;/span&gt; &lt;span class="kwrd"&gt;UNIQUE&lt;/span&gt; &lt;span class="kwrd"&gt;CLUSTERED&lt;/span&gt; &lt;span class="kwrd"&gt;INDEX&lt;/span&gt; cidx_v1 &lt;span class="kwrd"&gt;ON&lt;/span&gt; dbo.v1(c2, c3, c4, c1)
GO&lt;/pre&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;p&gt;For option 2 above, here’s the covering index:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;CREATE&lt;/span&gt; &lt;span class="kwrd"&gt;INDEX&lt;/span&gt; idx_PseudoClust &lt;span class="kwrd"&gt;ON&lt;/span&gt; t1(c3, c4) &lt;span class="kwrd"&gt;INCLUDE&lt;/span&gt; (c2, c1)
GO&lt;/pre&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;p&gt;So why would you want to do this?  I'm sure that there are some very good reasons, but I've never had the need to do it.  I recently had the discussion with a Microsoft engineer and thought it was interesting enough to share.&lt;/p&gt;&lt;img src="http://weblogs.sqlteam.com/tarad/aggbug/61047.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Tara Kizer</dc:creator>
            <guid>http://weblogs.sqlteam.com/tarad/archive/2009/11/09/Multiple-ldquoclusteredrdquo-indexes-on-a-SQL-Server-table.aspx</guid>
            <pubDate>Mon, 09 Nov 2009 19:23:05 GMT</pubDate>
            <wfw:comment>http://weblogs.sqlteam.com/tarad/comments/61047.aspx</wfw:comment>
            <comments>http://weblogs.sqlteam.com/tarad/archive/2009/11/09/Multiple-ldquoclusteredrdquo-indexes-on-a-SQL-Server-table.aspx#feedback</comments>
            <wfw:commentRss>http://weblogs.sqlteam.com/tarad/comments/commentRss/61047.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Defragmenting/Rebuilding Indexes in SQL Server 2005 and 2008</title>
            <link>http://weblogs.sqlteam.com/tarad/archive/2009/11/03/DefragmentingRebuilding-Indexes-in-SQL-Server-2005-and-2008Again.aspx</link>
            <description>&lt;p&gt;I have modified isp_ALTER_INDEX, which is the stored procedure that I wrote and use to defragment/rebuild indexes in SQL Server 2005 and SQL Server 2008.  The code change has just one bug fix.  The bug would only have been encountered on SQL Server 2008 systems that have XML indexes that need to be rebuilt based upon the input parameters.  &lt;/p&gt;
&lt;p&gt;In SQL Server 2005, the sys.dm_db_index_physical_stats data management function outputted “XML INDEX” for the index_type_desc column when the index contained a column with the XML data type.  In SQL Server 2008, the DMF was modified so that you could have either “XML INDEX” or “PRIMARY XML INDEX” for XML indexes in the index_type_desc column. &lt;/p&gt;
&lt;p&gt;I don’t have any systems that use the XML data type, so it wasn’t until we had the SQL Server 2008 AdventureWorks database on a development system that we found the bug.&lt;/p&gt;
&lt;p&gt;Here’s the code change in case you are interested:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;SET&lt;/span&gt; @online = 
        &lt;span class="kwrd"&gt;CASE&lt;/span&gt;
            &lt;span class="kwrd"&gt;WHEN&lt;/span&gt; @indexType &lt;span class="kwrd"&gt;IN&lt;/span&gt; (&lt;span class="str"&gt;'XML INDEX'&lt;/span&gt;, &lt;span class="str"&gt;'PRIMARY XML INDEX'&lt;/span&gt;) &lt;span class="kwrd"&gt;THEN&lt;/span&gt; 0
            &lt;span class="kwrd"&gt;WHEN&lt;/span&gt; @indexType = &lt;span class="str"&gt;'NONCLUSTERED INDEX'&lt;/span&gt; &lt;span class="kwrd"&gt;AND&lt;/span&gt; @allocUnitType = &lt;span class="str"&gt;'LOB_DATA'&lt;/span&gt; &lt;span class="kwrd"&gt;THEN&lt;/span&gt; 0
            &lt;span class="kwrd"&gt;WHEN&lt;/span&gt; @lobData = 1 &lt;span class="kwrd"&gt;THEN&lt;/span&gt; 0
            &lt;span class="kwrd"&gt;WHEN&lt;/span&gt; @disabled = 1 &lt;span class="kwrd"&gt;THEN&lt;/span&gt; 0
            &lt;span class="kwrd"&gt;WHEN&lt;/span&gt; @partitionCount &amp;gt; 1 &lt;span class="kwrd"&gt;THEN&lt;/span&gt; 0
            &lt;span class="kwrd"&gt;ELSE&lt;/span&gt; 1
        &lt;span class="kwrd"&gt;END&lt;/span&gt;&lt;/pre&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
&lt;![CDATA[




.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;You can download the new version of the stored procedure &lt;a href="http://www.tarakizer.com/files/scripts/isp_ALTER_INDEX_11032009.zip"&gt;here&lt;/a&gt;.&lt;img src="http://weblogs.sqlteam.com/tarad/aggbug/61040.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Tara Kizer</dc:creator>
            <guid>http://weblogs.sqlteam.com/tarad/archive/2009/11/03/DefragmentingRebuilding-Indexes-in-SQL-Server-2005-and-2008Again.aspx</guid>
            <pubDate>Tue, 03 Nov 2009 19:04:36 GMT</pubDate>
            <wfw:comment>http://weblogs.sqlteam.com/tarad/comments/61040.aspx</wfw:comment>
            <comments>http://weblogs.sqlteam.com/tarad/archive/2009/11/03/DefragmentingRebuilding-Indexes-in-SQL-Server-2005-and-2008Again.aspx#feedback</comments>
            <wfw:commentRss>http://weblogs.sqlteam.com/tarad/comments/commentRss/61040.aspx</wfw:commentRss>
        </item>
        <item>
            <title>SQL Server Magazine web article about a tool I wrote</title>
            <link>http://weblogs.sqlteam.com/tarad/archive/2009/10/08/SQL-Server-Magazine-web-article-about-a-tool-I-wrote.aspx</link>
            <description>&lt;p&gt;&lt;span class="Apple-style-span" style="WORD-SPACING: 0px; FONT: medium 'Times New Roman'; TEXT-TRANSFORM: none; COLOR: rgb(0,0,0); TEXT-INDENT: 0px; WHITE-SPACE: normal; LETTER-SPACING: normal; BORDER-COLLAPSE: separate; orphans: 2; widows: 2; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px"&gt;&lt;span class="Apple-style-span" style="FONT-SIZE: 12px; COLOR: rgb(64,64,64); FONT-FAMILY: Arial, Helvetica, sans-serif"&gt;My &lt;a href="http://weblogs.sqlteam.com/tarad/archive/2008/12/16/How-to-track-database-growth-across-multiple-SQL-Server-instances.aspx"&gt;Database Growth Tracker tool&lt;/a&gt; is featured in a &lt;a href="http://www.sqlmag.com/"&gt;SQL Server Magazine&lt;/a&gt; web article that &lt;a href="http://www.quest.com/newsroom/Kevin-Kline.aspx"&gt;Kevin Kline&lt;/a&gt; wrote. &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class="Apple-style-span" style="WORD-SPACING: 0px; FONT: medium 'Times New Roman'; TEXT-TRANSFORM: none; COLOR: rgb(0,0,0); TEXT-INDENT: 0px; WHITE-SPACE: normal; LETTER-SPACING: normal; BORDER-COLLAPSE: separate; orphans: 2; widows: 2; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px"&gt;&lt;span class="Apple-style-span" style="FONT-SIZE: 12px; COLOR: rgb(64,64,64); FONT-FAMILY: Arial, Helvetica, sans-serif"&gt;Check out the web article &lt;a href="http://www.sqlmag.com/Articles/ArticleID/102370/102370.html"&gt;here&lt;/a&gt;!&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;br class="Apple-interchange-newline" /&gt;
&lt;/p&gt;&lt;img src="http://weblogs.sqlteam.com/tarad/aggbug/61020.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Tara Kizer</dc:creator>
            <guid>http://weblogs.sqlteam.com/tarad/archive/2009/10/08/SQL-Server-Magazine-web-article-about-a-tool-I-wrote.aspx</guid>
            <pubDate>Thu, 08 Oct 2009 18:20:51 GMT</pubDate>
            <wfw:comment>http://weblogs.sqlteam.com/tarad/comments/61020.aspx</wfw:comment>
            <comments>http://weblogs.sqlteam.com/tarad/archive/2009/10/08/SQL-Server-Magazine-web-article-about-a-tool-I-wrote.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://weblogs.sqlteam.com/tarad/comments/commentRss/61020.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Fix for CLR object execution error after attach/restore in SQL Server 2005</title>
            <link>http://weblogs.sqlteam.com/tarad/archive/2009/09/21/Fix-for-CLR-object-execution-error-after-attachrestore-in-SQL.aspx</link>
            <description>&lt;p&gt;After attaching or restoring a database to SQL Server 2005, you may encounter an error when executing a CLR object.  &lt;/p&gt; &lt;p&gt;Error:&lt;/p&gt; &lt;p&gt;&lt;font color="#ff0000"&gt;An error occurred in the Microsoft .NET Framework while trying to load assembly id 65538. The server may be running out of resources, or the assembly may not be trusted with PERMISSION_SET = EXTERNAL_ACCESS or UNSAFE.&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="http://support.microsoft.com/kb/918040"&gt;This KB article&lt;/a&gt; describes the issue and shows the fix, however it says the bug occurs when the database is attached/restored to a different SQL instance.  I’ve encountered the error three times now.  In at least one occurrence of the error, it has happened when I’ve restored the database to the same SQL instance.&lt;/p&gt; &lt;p&gt; &lt;/p&gt;&lt;p&gt;&lt;font color="#ff0000"&gt;&lt;/font&gt;&lt;/p&gt;Fix:  &lt;p&gt;&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;USE&lt;/span&gt; master
&lt;span class="kwrd"&gt;GO&lt;/span&gt;
&lt;span class="kwrd"&gt;ALTER&lt;/span&gt; &lt;span class="kwrd"&gt;DATABASE&lt;/span&gt; dbNameGoesHere &lt;span class="kwrd"&gt;SET&lt;/span&gt; TRUSTWORTHY &lt;span class="kwrd"&gt;ON&lt;/span&gt;

&lt;span class="kwrd"&gt;USE&lt;/span&gt; dbNameGoesHere
&lt;span class="kwrd"&gt;GO&lt;/span&gt;
&lt;span class="kwrd"&gt;EXEC&lt;/span&gt; sp_changedbowner &lt;span class="str"&gt;'sa'&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
}
]]&gt;&lt;/style&gt;
&lt;pre&gt;&lt;/pre&gt;&lt;img src="http://weblogs.sqlteam.com/tarad/aggbug/61012.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Tara Kizer</dc:creator>
            <guid>http://weblogs.sqlteam.com/tarad/archive/2009/09/21/Fix-for-CLR-object-execution-error-after-attachrestore-in-SQL.aspx</guid>
            <pubDate>Mon, 21 Sep 2009 17:55:25 GMT</pubDate>
            <wfw:comment>http://weblogs.sqlteam.com/tarad/comments/61012.aspx</wfw:comment>
            <comments>http://weblogs.sqlteam.com/tarad/archive/2009/09/21/Fix-for-CLR-object-execution-error-after-attachrestore-in-SQL.aspx#feedback</comments>
            <slash:comments>2</slash:comments>
            <wfw:commentRss>http://weblogs.sqlteam.com/tarad/comments/commentRss/61012.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Fast and Reliable Backup and Restore of VLDBs in SQL Server 2008</title>
            <link>http://weblogs.sqlteam.com/tarad/archive/2009/09/10/Fast-and-Reliable-Backup-and-Restore-of-VLDBs-in-SQL.aspx</link>
            <description>&lt;p&gt;The &lt;a href="http://sqlcat.com/Default.aspx"&gt;SQLCAT team&lt;/a&gt; released a very informative whitepaper regarding backup and recovery of very large databases in SQL Server 2008.  It is a must read if you are a SQL Server DBA.  Check it out &lt;a href="http://sqlcat.com/whitepapers/archive/2009/08/13/a-technical-case-study-fast-and-reliable-backup-and-restore-of-a-vldb-over-the-network.aspx"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;If you are not already following the SQLCAT team’s blogs and you are a SQL Server DBA, you need to get with the times and start following one of the best online resources for SQL Server.&lt;/p&gt;&lt;img src="http://weblogs.sqlteam.com/tarad/aggbug/61007.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Tara Kizer</dc:creator>
            <guid>http://weblogs.sqlteam.com/tarad/archive/2009/09/10/Fast-and-Reliable-Backup-and-Restore-of-VLDBs-in-SQL.aspx</guid>
            <pubDate>Thu, 10 Sep 2009 23:03:22 GMT</pubDate>
            <wfw:comment>http://weblogs.sqlteam.com/tarad/comments/61007.aspx</wfw:comment>
            <comments>http://weblogs.sqlteam.com/tarad/archive/2009/09/10/Fast-and-Reliable-Backup-and-Restore-of-VLDBs-in-SQL.aspx#feedback</comments>
            <wfw:commentRss>http://weblogs.sqlteam.com/tarad/comments/commentRss/61007.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Backup SQL Server 2005 and 2008 Databases</title>
            <link>http://weblogs.sqlteam.com/tarad/archive/2009/09/08/Backup-SQL-Server-2005-and-2008-Databases.aspx</link>
            <description>&lt;p&gt;I have modified isp_Backup, which is the stored procedure that I use to backup SQL Server databases.  This new version includes one bug fix and three new features:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Bug Fix – removed ReportServerTempdb from exclusion list &lt;/li&gt;    &lt;li&gt;Bug Fix – fixed file retention code to handle database names with spaces &lt;/li&gt;    &lt;li&gt;Feature – support for SQL Server 2008 including compression &lt;/li&gt;    &lt;li&gt;Feature – archive bit option &lt;/li&gt;    &lt;li&gt;Feature – COPY_ONLY option &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;I decided that excluding the ReportServerTempdb from the backups was unnecessary.  This database, used by Reporting Services, is in FULL recovery model by default, so this exclusion could have caused you to run out of space in its transaction log.&lt;/p&gt;  &lt;p&gt;Bryan Conlon, one of my blog readers, noticed that the file retention code was not working when a database name had spaces in it.  It took me a while to come up with a solution for this one, but I came up with a solution that involves an additional temporary table that stores just the file names and then synchronizes with the original temporary table that handles the dates.  If you are wondering why I don’t just use the FORFILES command along with the DEL command which probably wouldn’t have this bug, it is because you can’t use UNC paths with FORFILES.  I didn’t want to limit storage of backups to local or mapped drives.  To see a file retention solution that uses FORFILES with DEL, check out &lt;a href="http://www.mssqltips.com/tip.asp?tip=1618"&gt;this blog&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;The archive bit option was added in case you don’t want to delete files that haven’t been backed up to tape.  If you aren’t backing up your files to tape, then do not use this feature unless you are setting this option to true on the files.  The default value of this new input parameter is false, so you don’t need to do anything if you don’t want to use it.&lt;/p&gt;  &lt;p&gt;The COPY_ONLY option was added due to a feature request from one of my blog readers, “&lt;a href="http://thebakingdba.blogspot.com/"&gt;The Baking DBA&lt;/a&gt;”.  This option allows you to perform a backup without impacting the normal sequence of backups.  For more details on this, please check out the COPY_ONLY option in the &lt;a href="http://msdn.microsoft.com/en-us/library/ms186865.aspx"&gt;BACKUP DATABASE topic&lt;/a&gt; in SQL Server Books Online.&lt;/p&gt;  &lt;p&gt;I also dropped support for SQL Server 2000, so this new version only supports SQL Server 2005 and SQL Server 2008.  I decided to drop SQL Server 2000 support from this new version, and all future versions, as keeping it in there was making it harder to release new versions.  If you still need SQL Server 2000 support, like I do on a legacy system, then do not deploy this new version to those systems, simply use the &lt;a href="http://weblogs.sqlteam.com/tarad/archive/2009/04/07/Backup-SQL-Server-DatabasesAgain.aspx"&gt;last version&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;You can download the new version &lt;a href="http://www.tarakizer.com/files/scripts/isp_Backup_09082009.zip"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Thank you to Bryan Conlon for also testing and finding bugs in the “beta” version of the stored procedure.  All bugs that were found have been fixed.  Thanks Bryan!&lt;/p&gt;&lt;img src="http://weblogs.sqlteam.com/tarad/aggbug/61006.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Tara Kizer</dc:creator>
            <guid>http://weblogs.sqlteam.com/tarad/archive/2009/09/08/Backup-SQL-Server-2005-and-2008-Databases.aspx</guid>
            <pubDate>Tue, 08 Sep 2009 18:26:53 GMT</pubDate>
            <wfw:comment>http://weblogs.sqlteam.com/tarad/comments/61006.aspx</wfw:comment>
            <comments>http://weblogs.sqlteam.com/tarad/archive/2009/09/08/Backup-SQL-Server-2005-and-2008-Databases.aspx#feedback</comments>
            <slash:comments>2</slash:comments>
            <wfw:commentRss>http://weblogs.sqlteam.com/tarad/comments/commentRss/61006.aspx</wfw:commentRss>
        </item>
        <item>
            <title>How to remove a SQL Server distribution database if other methods fail</title>
            <link>http://weblogs.sqlteam.com/tarad/archive/2009/09/02/How-to-remove-a-SQL-Server-distribution-database-if-other.aspx</link>
            <description>&lt;p&gt;For various reasons, you may need to manually remove SQL Server replication.  Microsoft has a good &lt;a href="http://support.microsoft.com/kb/324401"&gt;KB article&lt;/a&gt; which shows how to do it.  It has always worked in the past, but I ran into a situation a couple of weeks ago where it couldn’t remove the distributor via sp_dropdistributor.  I don’t recall what error we were getting, but I didn’t have time to figure out what was wrong so with the help of a Microsoft engineer we were able to setup another distributor and then get replication working again.  Later I tried “drop database” command on the original distribution database, but it said it couldn’t be dropped since it was being used for replication.  It no longer was being used for replication, so it seemed to be orphaned. &lt;/p&gt;  &lt;p&gt;Yesterday, I opened a case with Microsoft to see how I could get rid of the orphaned distribution database.  It’s a simple fix:&lt;/p&gt;  &lt;p&gt;use master   &lt;br /&gt;go    &lt;br /&gt;alter database distribution set offline;    &lt;br /&gt;drop database distribution;&lt;/p&gt;&lt;img src="http://weblogs.sqlteam.com/tarad/aggbug/61004.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Tara Kizer</dc:creator>
            <guid>http://weblogs.sqlteam.com/tarad/archive/2009/09/02/How-to-remove-a-SQL-Server-distribution-database-if-other.aspx</guid>
            <pubDate>Wed, 02 Sep 2009 20:59:26 GMT</pubDate>
            <wfw:comment>http://weblogs.sqlteam.com/tarad/comments/61004.aspx</wfw:comment>
            <comments>http://weblogs.sqlteam.com/tarad/archive/2009/09/02/How-to-remove-a-SQL-Server-distribution-database-if-other.aspx#feedback</comments>
            <slash:comments>2</slash:comments>
            <wfw:commentRss>http://weblogs.sqlteam.com/tarad/comments/commentRss/61004.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Defragmenting/Rebuilding Indexes in SQL Server 2005 and 2008</title>
            <link>http://weblogs.sqlteam.com/tarad/archive/2009/08/31/DefragmentingRebuilding-Indexes-in-SQL-server-2005-and-2008.aspx</link>
            <description>&lt;p&gt;I have modified isp_ALTER_INDEX, which is the stored procedure that I use to defragment/rebuild indexes in SQL Server 2005 and 2008.  The new version has a minor bug fix.  &lt;/p&gt;  &lt;p&gt;Recently I was comparing the fragmentation results between the DETAILED and SAMPLED modes of sys.dm_db_index_physical_stats and noticed that the DETAILED mode had “duplicate” entries for indexes.  Due to this, my old code would have ran ALTER INDEX against the same index multiple times if you used DETAILED for @statsMode.  To fix this, I simply added “index_level = 0” to the WHERE clause of the sys.dm_db_index_physical_stats query.  &lt;/p&gt;  &lt;p&gt;I consider this to be a minor bug as most people can not afford to run sys.dm_db_index_physical_stats in DETAILED mode.  &lt;/p&gt;  &lt;p&gt;You can download the new version of the stored procedure &lt;a href="http://www.tarakizer.com/files/scripts/isp_ALTER_INDEX_08312009.zip"&gt;here&lt;/a&gt;.  Let me know if you run into any issues with it.&lt;/p&gt;&lt;img src="http://weblogs.sqlteam.com/tarad/aggbug/61002.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Tara Kizer</dc:creator>
            <guid>http://weblogs.sqlteam.com/tarad/archive/2009/08/31/DefragmentingRebuilding-Indexes-in-SQL-server-2005-and-2008.aspx</guid>
            <pubDate>Mon, 31 Aug 2009 16:50:58 GMT</pubDate>
            <wfw:comment>http://weblogs.sqlteam.com/tarad/comments/61002.aspx</wfw:comment>
            <comments>http://weblogs.sqlteam.com/tarad/archive/2009/08/31/DefragmentingRebuilding-Indexes-in-SQL-server-2005-and-2008.aspx#feedback</comments>
            <slash:comments>2</slash:comments>
            <wfw:commentRss>http://weblogs.sqlteam.com/tarad/comments/commentRss/61002.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Defragmenting/Rebuilding Indexes in SQL Server 2005</title>
            <link>http://weblogs.sqlteam.com/tarad/archive/2009/06/23/DefragmentingRebuilding-Indexes-in-SQL-Server-2005.aspx</link>
            <description>&lt;p&gt;UPDATE: A new version of this stored procedure is available.  Please check it out &lt;a href="http://weblogs.sqlteam.com/tarad/archive/2009/08/31/DefragmentingRebuilding-Indexes-in-SQL-server-2005-and-2008.aspx"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;I have modified isp_ALTER_INDEX, which is the stored procedure that I use to defragment/rebuild indexes in SQL Server 2005.  The changes include two bug fixes and one feature request.  &lt;/p&gt;
&lt;p&gt;The first bug fix was reported by Fedor Baydarov.  He found that @lobData was not being re-initialized to zero after a LOB data type was encountered.  This meant that the rest of the indexes to be processed were being done offline even if the online option was available.  &lt;a href="http://en.wikipedia.org/wiki/D'oh!"&gt;D’oh!&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The second bug fix is that it didn’t check for LOB data types of the included columns in a non-clustered index.  The online option is not available for this type of index, so the bug caused the stored procedure to fail when such a condition was encountered.  This bug fix might have been found by a blog reader, but I’m unable to find an email regarding it.  I came across the bug recently on a system that had such an index.&lt;/p&gt;
&lt;p&gt;The feature request was to add the option to do the sort operation in the tempdb database.  This is recommended if your tempdb is optimized according to best practices, such as by having a tempdb data file for each of the CPUs.  See &lt;a href="http://technet.microsoft.com/en-us/library/ms188388(SQL.90).aspx"&gt;ALTER INDEX topic in SQL Server Books Online&lt;/a&gt; for more details.&lt;/p&gt;
&lt;p&gt;You can download the new version of the stored procedure &lt;a href="http://www.tarakizer.com/files/scripts/isp_ALTER_INDEX_06232009.zip"&gt;here&lt;/a&gt;.  &lt;/p&gt;
&lt;p&gt;Let me know if you run into any issues with it.  I’d also be interested to hear if it works on SQL Server 2008.  &lt;/p&gt;&lt;img src="http://weblogs.sqlteam.com/tarad/aggbug/60939.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Tara Kizer</dc:creator>
            <guid>http://weblogs.sqlteam.com/tarad/archive/2009/06/23/DefragmentingRebuilding-Indexes-in-SQL-Server-2005.aspx</guid>
            <pubDate>Tue, 23 Jun 2009 21:48:22 GMT</pubDate>
            <comments>http://weblogs.sqlteam.com/tarad/archive/2009/06/23/DefragmentingRebuilding-Indexes-in-SQL-Server-2005.aspx#feedback</comments>
            <slash:comments>7</slash:comments>
            <wfw:commentRss>http://weblogs.sqlteam.com/tarad/comments/commentRss/60939.aspx</wfw:commentRss>
        </item>
        <item>
            <title>SQL Server Script to Display Job History</title>
            <link>http://weblogs.sqlteam.com/tarad/archive/2009/06/10/SQL-Server-Script-to-Display-Job-History.aspx</link>
            <description>&lt;p&gt;I was going through my scripts today and found one that I’d like to share.  &lt;/p&gt;  &lt;p&gt;This SQL Server script will display job history.  The benefit of this script over displaying it from the GUI is that you get to see the job durations quickly.  &lt;/p&gt; &lt;style type="text/css"&gt;&lt;![CDATA[






&lt;/div&gt;/div&gt;&lt;/div&gt;/td&gt;&lt;/tr&gt;/tbody&gt;&lt;/table&gt;/form&gt;&lt;/body&gt;/html&gt;]]&gt;&lt;/style&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;select&lt;/span&gt; job_name, run_datetime, run_duration
&lt;span class="kwrd"&gt;from&lt;/span&gt;
(
    &lt;span class="kwrd"&gt;select&lt;/span&gt; job_name, run_datetime,
        &lt;span class="kwrd"&gt;SUBSTRING&lt;/span&gt;(run_duration, 1, 2) + &lt;span class="str"&gt;':'&lt;/span&gt; + &lt;span class="kwrd"&gt;SUBSTRING&lt;/span&gt;(run_duration, 3, 2) + &lt;span class="str"&gt;':'&lt;/span&gt; +
        &lt;span class="kwrd"&gt;SUBSTRING&lt;/span&gt;(run_duration, 5, 2) &lt;span class="kwrd"&gt;AS&lt;/span&gt; run_duration
    &lt;span class="kwrd"&gt;from&lt;/span&gt;
    (
        &lt;span class="kwrd"&gt;select&lt;/span&gt; &lt;span class="kwrd"&gt;DISTINCT&lt;/span&gt;
            j.name &lt;span class="kwrd"&gt;as&lt;/span&gt; job_name, 
            run_datetime = &lt;span class="kwrd"&gt;CONVERT&lt;/span&gt;(DATETIME, RTRIM(run_date)) +  
                (run_time * 9 + run_time % 10000 * 6 + run_time % 100 * 10) / 216e4,
            run_duration = &lt;span class="kwrd"&gt;RIGHT&lt;/span&gt;(&lt;span class="str"&gt;'000000'&lt;/span&gt; + &lt;span class="kwrd"&gt;CONVERT&lt;/span&gt;(&lt;span class="kwrd"&gt;varchar&lt;/span&gt;(6), run_duration), 6)
        &lt;span class="kwrd"&gt;from&lt;/span&gt; msdb..sysjobhistory h
        &lt;span class="kwrd"&gt;inner&lt;/span&gt; &lt;span class="kwrd"&gt;join&lt;/span&gt; msdb..sysjobs j
        &lt;span class="kwrd"&gt;on&lt;/span&gt; h.job_id = j.job_id
    ) t
) t
&lt;span class="kwrd"&gt;order&lt;/span&gt; &lt;span class="kwrd"&gt;by&lt;/span&gt; job_name, run_datetime&lt;/pre&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[




.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;p&gt;I know I stole the code from the inner-most derived table from someone, but I didn’t make a note of the source. I did a quick search for the source, but I came up with too many possibilities.&lt;/p&gt;&lt;img src="http://weblogs.sqlteam.com/tarad/aggbug/60930.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Tara Kizer</dc:creator>
            <guid>http://weblogs.sqlteam.com/tarad/archive/2009/06/10/SQL-Server-Script-to-Display-Job-History.aspx</guid>
            <pubDate>Wed, 10 Jun 2009 18:29:17 GMT</pubDate>
            <comments>http://weblogs.sqlteam.com/tarad/archive/2009/06/10/SQL-Server-Script-to-Display-Job-History.aspx#feedback</comments>
            <slash:comments>2</slash:comments>
            <wfw:commentRss>http://weblogs.sqlteam.com/tarad/comments/commentRss/60930.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Backup SQL Server Databases</title>
            <link>http://weblogs.sqlteam.com/tarad/archive/2009/04/07/Backup-SQL-Server-DatabasesAgain.aspx</link>
            <description>&lt;p&gt;EDIT: new version of stored procedure is located &lt;a href="http://weblogs.sqlteam.com/tarad/archive/2009/09/08/Backup-SQL-Server-2005-and-2008-Databases.aspx"&gt;here&lt;/a&gt;.  Use the new version for 2005/2008.  Use the below version for 2000.&lt;/p&gt;
&lt;p&gt;I have modified isp_Backup, which is the stored procedure that I use to backup SQL Server databases.  In this version, I fixed two bug and added a feature.  Here are the changes:&lt;/p&gt;
&lt;ol&gt;
    &lt;li&gt;Fixed "2000 backupset" bug by qualifying the object to msdb.dbo.backupset &lt;/li&gt;
    &lt;li&gt;Fixed the full backup check for SIMPLE recovery model databases (bug found by Eugene from &lt;a href="http://www.perfspot.com/Default.asp?"&gt;PerfSpot.com&lt;/a&gt;) &lt;/li&gt;
    &lt;li&gt;Added &lt;a target="_blank" href="http://www.red-gate.com/"&gt;Red Gate&lt;/a&gt; &lt;a target="_blank" href="http://www.red-gate.com/products/sql_backup/index_2.htm"&gt;SQL Backup&lt;/a&gt; functionality &lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;If you have scheduled jobs that are using any of my previous versions, you might need to modify the job step so that it uses the new @bkpSwType input parameter rather than the @liteSpeed parameter.&lt;/p&gt;
&lt;p&gt;You can download the revised stored procedure &lt;a href="http://www.tarakizer.com/files/scripts/isp_Backup_04072009.zip"&gt;here&lt;/a&gt;.  &lt;/p&gt;
&lt;p&gt;In the download, I have provided a script, ModifyJobStep.sql, to update the job step by replacing @liteSpeed with @bkpSwType.  This only needs to be run if the job step includes @liteSpeed.  You may not have this if you were using native backups since "@liteSpeed = N" was the default.  If the script fails, run it one more time.  There is some sort of SQL Server bug that is encountered on some systems, but it doesn't appear if you run it a second time.  It is not a bug with the script though.&lt;/p&gt;
&lt;p&gt;Let me know if you encounter any issues with this version so that I can get them fixed.  &lt;/p&gt;
&lt;p&gt;In the next version, I will add support for SQL Server 2008.  It is a rather quick modification, but I need to do some additional testing of it before I release it to the Internet.  If you'd like the next version before I finish my testing, just &lt;a target="_blank" href="http://weblogs.sqlteam.com/tarad/contact.aspx"&gt;send me an email&lt;/a&gt;.&lt;/p&gt;&lt;img src="http://weblogs.sqlteam.com/tarad/aggbug/60890.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Tara Kizer</dc:creator>
            <guid>http://weblogs.sqlteam.com/tarad/archive/2009/04/07/Backup-SQL-Server-DatabasesAgain.aspx</guid>
            <pubDate>Tue, 07 Apr 2009 20:00:06 GMT</pubDate>
            <comments>http://weblogs.sqlteam.com/tarad/archive/2009/04/07/Backup-SQL-Server-DatabasesAgain.aspx#feedback</comments>
            <slash:comments>7</slash:comments>
            <wfw:commentRss>http://weblogs.sqlteam.com/tarad/comments/commentRss/60890.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Defragmenting Indexes in SQL Server 2005</title>
            <link>http://weblogs.sqlteam.com/tarad/archive/2009/03/27/Defragmenting-Indexes-in-SQL-Server-2005Again.aspx</link>
            <description>&lt;p&gt;I have modified isp_ALTER_INDEX, which is the stored procedure that I use to defragment indexes in SQL Server 2005.  The changes include one bug fix and one feature request.  &lt;/p&gt;  &lt;p&gt;The bug fix was simply to add "SET QUOTED_IDENTIFIER ON" to the script.  You'd only see the bug in special circumstances, such as if you were using indexed views.  &lt;/p&gt;  &lt;p&gt;The feature request was to add the ability to log the fragmentation data.  The logged data could be used to determine if you want to rearrange the index or perhaps add/remove columns to reduce fragmentation.  The logged data is stored in a table called DefragmentIndexes.  If you don't want to log the data, then you'll still need to create the table if you want to use this new version, otherwise the CREATE PROC statement would fail due to a missing object.  To configure the stored procedure to log the data, simply pass 1 to the new input parameter, @logHistory.  The default for this new input parameter is 0, so you do not need to modify your job if you don't care about this new feature.  &lt;/p&gt;  &lt;p&gt;You can download the new version of the stored procedure and the required table &lt;a href="http://www.tarakizer.com/files/scripts/isp_ALTER_INDEX_03272009.zip" target="_blank"&gt;here&lt;/a&gt;.  I put them in the same script to make it easier to deploy the new version.&lt;/p&gt;  &lt;p&gt;Let me know if you run into any issues with it.&lt;/p&gt;&lt;img src="http://weblogs.sqlteam.com/tarad/aggbug/60883.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Tara Kizer</dc:creator>
            <guid>http://weblogs.sqlteam.com/tarad/archive/2009/03/27/Defragmenting-Indexes-in-SQL-Server-2005Again.aspx</guid>
            <pubDate>Fri, 27 Mar 2009 19:30:51 GMT</pubDate>
            <comments>http://weblogs.sqlteam.com/tarad/archive/2009/03/27/Defragmenting-Indexes-in-SQL-Server-2005Again.aspx#feedback</comments>
            <slash:comments>6</slash:comments>
            <wfw:commentRss>http://weblogs.sqlteam.com/tarad/comments/commentRss/60883.aspx</wfw:commentRss>
        </item>
        <item>
            <title>FastCopy - fastest Windows copy product?</title>
            <link>http://weblogs.sqlteam.com/tarad/archive/2009/03/03/FastCopy---fastest-Windows-copy-product.aspx</link>
            <description>&lt;p&gt;If you've ever had to copy large files on a Windows platform using the Windows copy method (copy/paste in Windows Explorer or copy/xcopy commands), then you know how slow it is.  Recently I had to setup database mirroring for a largish database, so I needed to copy the full backup to the mirror server.  The database is about 110 GB in size, but since we use &lt;a href="http://www.quest.com/" target="_blank"&gt;Quest&lt;/a&gt;'s &lt;a href="http://www.quest.com/litespeed-for-sql-server/" target="_blank"&gt;LiteSpeed&lt;/a&gt; product, the full backup is just 35.8 GB in size.  I had heard about FastCopy, which claims to be the fastest Windows copy product, so I decided to do comparison tests.  &lt;/p&gt;  &lt;p&gt;Using the Windows copy method, the 35.8 GB file was successfully copied across the WAN in 2 hours and 15 minutes.  Using FastCopy, it copied in 1 hour and 53 minutes.  FastCopy was about 16% faster than the Windows copy method.  &lt;/p&gt;  &lt;p&gt;I then tried copying an 11.7 GB file in a different environment, one where file copies seem to take forever over the WAN.  Using the normal Windows copy method, the 11.7 GB file copied across the WAN in 55 minutes.  Using FastCopy, it copied in 51 minutes.  FastCopy was only about 7% faster.&lt;/p&gt;  &lt;p&gt;Both of the above tests were done on compressed files.  Since I wasn't seeing much of a performance boost with FastCopy, I then tested with uncompressed files.  &lt;/p&gt;  &lt;p&gt;The first uncompressed file was 51.6 GB in size.  That file took 4 hours and 3 minutes using Windows copy method and 3 hours and 16 minutes using FastCopy.  That's a 19% improvement.  &lt;/p&gt;  &lt;p&gt;The second uncompressed file was 15.6 GB in size.  That file took 2 hours and 32 minutes using Windows copy method and 2 hours and 23 minutes using FastCopy.  That's a 6% improvement.  By the way, I was getting about 1.85 MB per second for the transfer rate on this system, so that's why these times are so bad.  On the other ones, I was getting around 4.75 MB per second.&lt;/p&gt;  &lt;p&gt;FastCopy provides a command-line interface as well, so it can be used in batch files and scheduled jobs, such as those that &lt;a href="http://weblogs.sqlteam.com/tarad/archive/2009/02/25/How-to-refresh-a-SQL-Server-database-automatically.aspx" target="_blank"&gt;refresh your development/test databases with production data&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;If you don't mind the cluttered GUI and the poorly translated to English documentation, then I'd recommend this product.  You can download and read more about FastCopy &lt;a href="http://www.ipmsg.org/tools/fastcopy.html.en" target="_blank"&gt;here&lt;/a&gt;.  &lt;/p&gt;  &lt;p&gt;There are other products out there that claim to be faster than the Windows copy method, such as &lt;a href="http://en.wikipedia.org/wiki/Robocopy" target="_blank"&gt;Robocopy&lt;/a&gt; and &lt;a href="http://www.codesector.com/teracopy.php" target="_blank"&gt;TeraCopy&lt;/a&gt;, but I did not compare them to FastCopy.  If you already performed these comparisons, please let me know.&lt;/p&gt;&lt;img src="http://weblogs.sqlteam.com/tarad/aggbug/60862.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Tara Kizer</dc:creator>
            <guid>http://weblogs.sqlteam.com/tarad/archive/2009/03/03/FastCopy---fastest-Windows-copy-product.aspx</guid>
            <pubDate>Tue, 03 Mar 2009 23:35:18 GMT</pubDate>
            <comments>http://weblogs.sqlteam.com/tarad/archive/2009/03/03/FastCopy---fastest-Windows-copy-product.aspx#feedback</comments>
            <slash:comments>20</slash:comments>
            <wfw:commentRss>http://weblogs.sqlteam.com/tarad/comments/commentRss/60862.aspx</wfw:commentRss>
        </item>
        <item>
            <title>SQL Server 2008 System Views Map</title>
            <link>http://weblogs.sqlteam.com/tarad/archive/2009/02/27/SQL-Server-2008-System-Views-Map.aspx</link>
            <description>&lt;p&gt;&lt;font face="Arial"&gt;Microsoft published the ERD for the system views about a month ago, but I'm just now seeing it.  It is available in PDF or XPS format.  &lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;You can download them &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=531c53e7-8a2a-4375-8f2f-5d799aa67b5c&amp;amp;displaylang=en"&gt;here&lt;/a&gt;.&lt;/font&gt;&lt;/p&gt;&lt;img src="http://weblogs.sqlteam.com/tarad/aggbug/60858.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Tara Kizer</dc:creator>
            <guid>http://weblogs.sqlteam.com/tarad/archive/2009/02/27/SQL-Server-2008-System-Views-Map.aspx</guid>
            <pubDate>Fri, 27 Feb 2009 18:53:41 GMT</pubDate>
            <comments>http://weblogs.sqlteam.com/tarad/archive/2009/02/27/SQL-Server-2008-System-Views-Map.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://weblogs.sqlteam.com/tarad/comments/commentRss/60858.aspx</wfw:commentRss>
        </item>
        <item>
            <title>How to refresh a SQL Server database automatically</title>
            <link>http://weblogs.sqlteam.com/tarad/archive/2009/02/25/How-to-refresh-a-SQL-Server-database-automatically.aspx</link>
            <description>&lt;p&gt;As a DBA, we are often asked to refresh a database, which means to overwrite an existing database using a different database's backup.  If you are rarely asked to do this, you may decide to do it manually.  If you are asked to do this on a regular and perhaps scheduled basis, then you'd want to automate it.  Developers often want to write and debug code against a copy of the production database, so it makes sense to refresh their databases on a daily or weekly basis.  &lt;/p&gt;
&lt;p&gt;If you were to do the refresh manually, you would probably follow these steps more or less: &lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;Copy the backup file &lt;/li&gt;
    &lt;li&gt;Restore the database &lt;/li&gt;
    &lt;li&gt;Unorphan the accounts if the SIDs aren't in sync &lt;/li&gt;
    &lt;li&gt;Provide db_owner or similar permissions to the development staff &lt;/li&gt;
    &lt;li&gt;Run a script for anything else not handled above &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Depending upon the size of the backup, you may want to compress it after the first step from above using tools like &lt;a target="_blank" href="http://www.rarlab.com/"&gt;WinRAR&lt;/a&gt;, &lt;a target="_blank" href="http://www.pkware.com/software-pkzip"&gt;PKZIP&lt;/a&gt;, or &lt;a target="_blank" href="http://www.winzip.com/index.htm"&gt;WinZip&lt;/a&gt;.  These three tools have command line versions, so it can be easily added to the refresh process. &lt;/p&gt;
&lt;p&gt;To automate this process, we need to write code that does the above steps and then to schedule that code to run via the SQL Server Agent.  To make this easier to understand, I will be referring to the source server as Server1 and the destination server as Server2.  An example of a source server is production, and an example of a destination server is development. &lt;/p&gt;
&lt;p&gt;Here's how I have the refresh automated in a couple of my environments: &lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;On Server1, a job exists that compresses the latest full backup &lt;/li&gt;
    &lt;li&gt;On Server2, there's a job that performs the following steps:
    &lt;ul&gt;
        &lt;li&gt;Copies the compressed file to a local drive &lt;/li&gt;
        &lt;li&gt;Decompresses the file to make the full backup available &lt;/li&gt;
        &lt;li&gt;Kills all sessions to the database that is about to be restored &lt;/li&gt;
        &lt;li&gt;Restores the database &lt;/li&gt;
        &lt;li&gt;Sets the recovery model to Simple &lt;/li&gt;
        &lt;li&gt;Grants db_owner privileges to the developers &lt;/li&gt;
    &lt;/ul&gt;
    &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;You'll need to schedule the job on Server2 so that it doesn't run until the job on Server1 completes.  I just watch how long the job on Server1 takes and then schedule the job on Server2 to run a few hours afterwards.  &lt;/p&gt;
&lt;p&gt;You can download all of my code &lt;a target="_blank" href="http://www.tarakizer.com/files/scripts/Refresh.zip"&gt;here&lt;/a&gt;.  The file for Server1 is named RefreshServer1.sql, and the file for Server2 is named RefreshServer2.sql.  I perform all of the steps on Server2 in a single stored procedure, which means I only have one job step.  &lt;/p&gt;
&lt;p&gt;In the code, you'll notice that I am using rar.exe and CPAU.exe.  Your refresh process may not need these.  &lt;/p&gt;
&lt;p&gt;We use WinRAR as our compression utility.  WinRAR's command line version is rar.exe.  CPAU.exe is used to provide credentials to authenticate to Server1 as Server1 and Server2 are in different domains in my environment, and unfortunately we don't have a trust relationship setup between the two domains.  For more information on CPAU, see &lt;a target="_blank" href="http://weblogs.sqlteam.com/tarad/archive/2008/08/25/How-to-run-a-process-using-different-credentials.aspx"&gt;this blog post&lt;/a&gt;.  In the comments, I included the restore command if you are using &lt;a target="_blank" href="http://www.quest.com/"&gt;Quest&lt;/a&gt;'s &lt;a target="_blank" href="http://www.quest.com/litespeed-for-sql-server/"&gt;LiteSpeed&lt;/a&gt;.  We use it for our backups, so we use their xp_restore_database extended stored procedure to restore them. &lt;/p&gt;
&lt;p&gt;I don't have any code to unorphan the accounts in my refresh process as I ensure that the SIDs are identical between the two environments.  For more information on that, see &lt;a target="_blank" href="http://weblogs.sqlteam.com/tarad/archive/2008/06/24/How-to-transfer-SQL-logins-between-SQL-Server-2005-instances.aspx"&gt;this blog post&lt;/a&gt;.  In case you need a script to unorphan the accounts, I've included it in the download as UnorphanAccounts.sql. &lt;/p&gt;
&lt;p&gt;You can easily rewrite the code to handle multiple databases that need to be refreshed on the same Server1 and Server2.  In fact, that's what I am doing in my environments as some of the applications that I support use multiple databases.  To handle multiple databases on the same instances, you'll need to loop through them in isp_RefreshServer1.  My looping code is in there, but it is commented out.  You'll also need to perform multiple restores in isp_RefreshServer2.  I left the code for multiple databases in that stored procedure too, but I commented it out.  &lt;/p&gt;
&lt;p&gt;If you have a lot of databases to refresh and they all follow the same code, I would suggest parameterizing the stored procedures rather than hard-coding the various things.  &lt;/p&gt;&lt;img src="http://weblogs.sqlteam.com/tarad/aggbug/60855.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Tara Kizer</dc:creator>
            <guid>http://weblogs.sqlteam.com/tarad/archive/2009/02/25/How-to-refresh-a-SQL-Server-database-automatically.aspx</guid>
            <pubDate>Wed, 25 Feb 2009 20:32:16 GMT</pubDate>
            <comments>http://weblogs.sqlteam.com/tarad/archive/2009/02/25/How-to-refresh-a-SQL-Server-database-automatically.aspx#feedback</comments>
            <slash:comments>8</slash:comments>
            <wfw:commentRss>http://weblogs.sqlteam.com/tarad/comments/commentRss/60855.aspx</wfw:commentRss>
        </item>
    </channel>
</rss>
