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

<channel>
	<title>Prism IT Services Sydney &#187; SharePoint</title>
	<atom:link href="http://prism-it-services.com.au/blog/category/sharepoint/feed/" rel="self" type="application/rss+xml" />
	<link>http://prism-it-services.com.au/blog</link>
	<description>Simon Bailey, Prism IT Services Sydney</description>
	<lastBuildDate>Sun, 30 Aug 2009 01:05:33 +0000</lastBuildDate>
	
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Defrag SharePoint with SQL Server Express</title>
		<link>http://prism-it-services.com.au/blog/defrag-sharepoint-with-sql-server-express/</link>
		<comments>http://prism-it-services.com.au/blog/defrag-sharepoint-with-sql-server-express/#comments</comments>
		<pubDate>Sat, 06 Jun 2009 10:48:38 +0000</pubDate>
		<dc:creator>Simon Bailey</dc:creator>
				<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[defrag]]></category>
		<category><![CDATA[SQL Server Express]]></category>
		<category><![CDATA[SSEE]]></category>

		<guid isPermaLink="false">http://prism-it-services.com.au/?p=177</guid>
		<description><![CDATA[Use this script to defrag SharePoint 3.0 with SQL Server Express (SSEE).]]></description>
			<content:encoded><![CDATA[<p>If you are using SharePoint 3.0 with Service Pack 2, <a href="http://support.microsoft.com/kb/943345">Microsoft article 943345</a> says that defrag occurs automatically &#8211; so long as you have the full edition of SQL Server 2005.</p>
<p>If you are using SQL Server Express Edition (SSEE), you can use the script given in that article &#8211; but you need to adjust it slightly.</p>
<p>SSEE won&#8217;t do an online defrag, so the script needs to be changed to always perform an offline defrag.  You also need to find out the name of your <strong>content database</strong> and include that at the start of the script.</p>
<p>Now all you need to do is take your content database offline (you do that from the Applications Management page in your SharePoint website), and run the script.</p>
<p>The SQL script below is a copy of Microsoft&#8217;s script with slight modifications to make it work on SSEE.</p>
<pre>
use <span class="highlight">WSS_Content_Database</span>;

    SET NOCOUNT ON
    DECLARE @objectid int
    DECLARE @indexid int
    DECLARE @command varchar(8000)
    DECLARE @baseCommand varchar(8000)
    DECLARE @schemaname sysname
    DECLARE @objectname sysname
    DECLARE @indexname sysname
    DECLARE @currentDdbId int
    SELECT @currentDdbId = DB_ID()

    PRINT CONVERT(nvarchar, GETDATE(), 126) + ': Starting'

    -- Loop over each of the indices
    DECLARE indexesToDefrag CURSOR FOR 
    SELECT 
        i.object_id, 
        i.index_id, 
        i.name
    FROM 
        sys.indexes AS i
    INNER JOIN 
        sys.objects AS o
    ON
        i.object_id = o.object_id
    WHERE 
        i.index_id &gt; 0 AND
        o.type = 'U'

    OPEN indexesToDefrag
    -- Loop through the partitions.
    FETCH NEXT
    FROM
        indexesToDefrag
    INTO 
        @objectid, 
        @indexid,
        @indexname
    WHILE @@FETCH_STATUS = 0
    BEGIN
        -- Lookup the name of the index
        SELECT 
            @schemaname = s.name
        FROM 
            sys.objects AS o
        JOIN 
            sys.schemas AS s
        ON
            s.schema_id = o.schema_id
        WHERE
            o.object_id = @objectid

        PRINT CONVERT(nvarchar, GETDATE(), 126) + ': ' + @schemaname + '.' + @indexname + ' is now being rebuilt.'

        -- Fragmentation is bad enough that it will be more efficient to rebuild the index
        SELECT @baseCommand = 
            ' ALTER INDEX ' + 
                @indexname +
            ' ON ' + 
                @schemaname + '.' + object_name(@objectid) + 
            ' REBUILD WITH (FILLFACTOR = 80, ONLINE = '

        -- Use dynamic sql so this compiles in SQL 2000
        SELECT @command =
               @baseCommand + 'OFF) '

        PRINT CONVERT(nvarchar, GETDATE(), 126) + ': Rebuilding'
        EXEC (@command)
        PRINT CONVERT(nvarchar, GETDATE(), 126) + ': Done'

        FETCH NEXT FROM indexesToDefrag INTO @objectid, @indexid, @indexname
    END
    CLOSE indexesToDefrag
    DEALLOCATE indexesToDefrag
</pre>

]]></content:encoded>
			<wfw:commentRss>http://prism-it-services.com.au/blog/defrag-sharepoint-with-sql-server-express/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
