Skip to content

Keeping your SharePoint 2010 development databases small

With SharePoint 2010 the number of databases on your SQL Server has grown quite a bit. By default, most of these databases have their recovery model set to FULL. After some time, you will discover you’re running out of space.

The problem

Most likely, the problem lies with the transaction logs of your databases. With the recovery model set to FULL they will keep storing every transaction until you make a backup. Chances are you do not configure a backup plan for your development environment as most development databases do not need a backup as your sources will be stored in a source control system.

The (manual) solution

To solve this problem, you can change the recovery model of each database by hand. For this you can open SMSS (SQL Server Management Studio), open the properties screen for a database and navigate to the options tab. There you will find the recovery model option.

Database Properties screen with the Recovery model set to 'Simple'
Database Properties screen with the Recovery model set to Simple.

Saving this change will empty your transaction log. But it will not shrink the physical file on disk. To shrink this file, you can look at the Shrink task.

The context menu's to shrink the size of the log files
The context menus to shrink the size of the log files.

The (automated) solution

Executing this step for every database manually is quite some work. So, you want the easy solution.

The following TSQL script will change the recovery model for every database to Simple and shrinks the database.

USE [master]

DECLARE @altercmd NVARCHAR(1000)
DECLARE @shrinkcmd NVARCHAR(1000)

DECLARE [dbcursor] CURSOR FOR SELECT [name] FROM sysdatabases

OPEN [dbcursor]
FETCH NEXT FROM [dbcursor] INTO @dbname

    @dbname != 'tempdb'
    SET @altercmd = 'ALTER DATABASE "' + @dbname + '" SET RECOVERY SIMPLE'
      EXEC (@altercmd)

      SET @shrinkcmd = 'DBCC SHRINKDATABASE ("' + @dbname + '")'
      EXEC (@shrinkcmd)

      PRINT @dbname

  FETCH NEXT FROM [dbcursor] INTO @dbname

CLOSE [dbcursor]
DEALLOCATE [dbcursor]