<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Shared Points for SharePoint : SQL</title><link>http://blogs.msdn.com/mcsnoiwb/archive/tags/SQL/default.aspx</link><description>Tags: SQL</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Lots of databases, full recovery model, low disk space...what to do?</title><link>http://blogs.msdn.com/mcsnoiwb/archive/2008/05/22/lots-of-databases-full-recovery-model-low-disk-space-what-to-do.aspx</link><pubDate>Thu, 22 May 2008 18:26:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8531931</guid><dc:creator>Stian Kirkeberg</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/mcsnoiwb/comments/8531931.aspx</comments><wfw:commentRss>http://blogs.msdn.com/mcsnoiwb/commentrss.aspx?PostID=8531931</wfw:commentRss><description>&lt;P&gt;I do not much care for having my development databases set to Recovery modell = full. There is really no need for that. The day I need to restore a logfile the environmnet better be a production environment. &lt;/P&gt;
&lt;P&gt;Unfortunatly SQL 2005 let me set the Recovery model on a global level (Please tell me how if it really does - I'm no core SQL guy.). I know it let's you set default file locations etc. and that is good.&lt;/P&gt;
&lt;P&gt;The problems starts when SharePoint creates the db's for you, because you never remember to go in to the SQL server and change the recovery model to simple. Then shrink the log file to save the space... It is simply to unconvenient.&lt;/P&gt;
&lt;P&gt;Running low on disk space, this problem had to dealt with. But to change some hundred databases manually is of course out of the question. So I wrote a small script to take care of it. &lt;/P&gt;
&lt;P&gt;The Script first alters the recovery model, then shrinks the file. Remember to set the starting point for your databases. In my example I have 7 system databases and the rest is SharePoint db's. Be carefull not to make changes to any database not used for development only. &lt;/P&gt;
&lt;P&gt;Do a check on&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;select name, database_id from sys.databases order by database_id&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;TABLE class="" cellSpacing=0 cellPadding=2 width=1015 border=1&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="" vAlign=top width=1013&gt;
&lt;P&gt;USE [master]&lt;/P&gt;
&lt;P&gt;GO&lt;/P&gt;
&lt;P&gt;DECLARE @dbname nvarchar(128)&lt;/P&gt;
&lt;P&gt;DECLARE @filename nvarchar(128)&lt;/P&gt;
&lt;P&gt;DECLARE @cmd nvarchar(500)&lt;/P&gt;
&lt;P&gt;DECLARE @SQLString NVARCHAR(500)&lt;/P&gt;
&lt;P&gt;DECLARE @ParmDefinition NVARCHAR(500)&lt;/P&gt;
&lt;P&gt;DECLARE @getdbnames CURSOR&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SET @getdbnames = CURSOR FOR&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select name from sys.databases where database_id &amp;gt; 7 order by database_id&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;OPEN @getdbnames&lt;/P&gt;
&lt;P&gt;FETCH NEXT&lt;/P&gt;
&lt;P&gt;FROM @getdbnames INTO @dbname&lt;/P&gt;
&lt;P&gt;WHILE @@FETCH_STATUS = 0&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;BEGIN&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;SET @cmd = N'ALTER DATABASE "' + @dbname + '"&lt;/P&gt;
&lt;P&gt;SET RECOVERY SIMPLE WITH NO_WAIT' + CHAR(13)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; + N'ALTER DATABASE "' + @dbname&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; + '" SET RECOVERY SIMPLE '&lt;/P&gt;
&lt;P&gt;EXECUTE sp_executesql @cmd&lt;/P&gt;
&lt;P&gt;SET @SQLString =N'select @filenameOUT = name FROM "' + @dbName + '".sys.database_files where type_desc = ''Log'''&lt;/P&gt;
&lt;P&gt;SET @ParmDefinition = N'@filenameOUT&lt;/P&gt;
&lt;P&gt;varchar(300) OUTPUT'&lt;/P&gt;
&lt;P&gt;EXECUTE sp_executesql @SQLString, @ParmDefinition, @filenameOUT=@filename OUTPUT&lt;/P&gt;
&lt;P&gt;SELECT @filename&lt;/P&gt;
&lt;P&gt;SET @cmd = N'USE "' + @dbname + '" DBCC SHRINKFILE (N''' + @filename +''' , 0, TRUNCATEONLY)'&lt;/P&gt;
&lt;P&gt;EXECUTE sp_executesql @cmd&lt;/P&gt;
&lt;P&gt;FETCH NEXT FROM @getdbnames INTO @dbname&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;END&lt;/P&gt;
&lt;P&gt;CLOSE @getdbnames&lt;/P&gt;
&lt;P&gt;DEALLOCATE @getdbnames&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;
&lt;P&gt;&lt;EM&gt;Please note that this approach is not recommended to test and production environments. Leave SharePoint databases to their default settings there. &lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;The change run supprisingly fast (there is a lot of disk I/O here) and I got a lot of free space on the server again! :)&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit:&lt;/P&gt;
&lt;P&gt;Just got a reply from Michael in Austria. He says:&lt;/P&gt;
&lt;P class=MsoPlainText style="MARGIN: 0cm 0cm 0pt"&gt;&lt;FONT face=Consolas&gt;&lt;EM&gt;Everytime you create a new database SQL Server "clones" its "Model" database. So by setting your appreciate recovery model at this database, it will be default for every new one.&lt;/EM&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoPlainText style="MARGIN: 0cm 0cm 0pt"&gt;&lt;FONT face=Consolas&gt;&lt;EM&gt;I have tested it for SQL Server 2000 but it should be the same for all other editions.&lt;/EM&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoPlainText style="MARGIN: 0cm 0cm 0pt"&gt;&lt;FONT face=Consolas&gt;&lt;EM&gt;You can get more information about the model database here: &lt;/EM&gt;&lt;/FONT&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/ms186388.aspx" mce_href="http://msdn.microsoft.com/en-us/library/ms186388.aspx"&gt;&lt;FONT face=Consolas color=#0000ff&gt;&lt;EM&gt;http://msdn.microsoft.com/en-us/library/ms186388.aspx&lt;/EM&gt;&lt;/FONT&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P class=MsoPlainText style="MARGIN: 0cm 0cm 0pt" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoPlainText style="MARGIN: 0cm 0cm 0pt"&gt;Thanks, Michael! :)&lt;/P&gt;
&lt;P class=MsoPlainText style="MARGIN: 0cm 0cm 0pt" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoPlainText style="MARGIN: 0cm 0cm 0pt" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8531931" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/mcsnoiwb/archive/tags/Sharepoint/default.aspx">Sharepoint</category><category domain="http://blogs.msdn.com/mcsnoiwb/archive/tags/SharePoint+development/default.aspx">SharePoint development</category><category domain="http://blogs.msdn.com/mcsnoiwb/archive/tags/Content+Database/default.aspx">Content Database</category><category domain="http://blogs.msdn.com/mcsnoiwb/archive/tags/Upgrade/default.aspx">Upgrade</category><category domain="http://blogs.msdn.com/mcsnoiwb/archive/tags/SQL/default.aspx">SQL</category></item><item><title>Heros happen here</title><link>http://blogs.msdn.com/mcsnoiwb/archive/2008/02/01/heros-happen-here.aspx</link><pubDate>Fri, 01 Feb 2008 23:32:59 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7378126</guid><dc:creator>Stian Kirkeberg</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/mcsnoiwb/comments/7378126.aspx</comments><wfw:commentRss>http://blogs.msdn.com/mcsnoiwb/commentrss.aspx?PostID=7378126</wfw:commentRss><description>&lt;p&gt;Guess you have heard about the &lt;a href="http://www.microsoft.com/heroeshappenhere/default.mspx" target="_blank"&gt;Heros happen here campaign&lt;/a&gt;?&amp;nbsp; Seen their &lt;a href="http://www.microsoft.com/heroeshappenhere/cool-stuff/comic/default.mspx" target="_blank"&gt;daily comic&lt;/a&gt;? Worth a peek! :)&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=7378126" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/mcsnoiwb/archive/tags/Visual+Studio/default.aspx">Visual Studio</category><category domain="http://blogs.msdn.com/mcsnoiwb/archive/tags/SQL/default.aspx">SQL</category></item></channel></rss>