How do I set an SQL Server database's recovery mode to simple using a script?

Posted: (EET/GMT+2)

 

Changing SQL Server database's recovery model to SIMPLE reduces transaction log growth when you don't need point-in-time restore capability. You can change the recovery mode directly with a single T-SQL command.

Here's an example:

ALTER DATABASE [MyDatabase] SET RECOVERY SIMPLE;
GO

-- Optionally shrink the log file if it has grown large
DBCC SHRINKFILE (MyDatabase_Log, 1);
GO

With these commands executed, you can verify the change:

SELECT name, recovery_model_desc
FROM sys.databases
WHERE name = 'MyDatabase';

Use the SIMPLE recovery for development, reporting, or non-critical databases. For production systems where you need point-in-time restore, use FULL recovery and take regular log backups.