Previous Code Entry
Left Arrow
SQL Server Management Studio - Restore database
Current Code Entry
Next Code Entry
SQL Server Management Studio - List all tables in a database
Right Arrow
SQL Server Management Studio - Change Recovery Model to Simple
Article Entry Date: July 10,2022 @ 01:51:33 / Last Updated On: July 10,2022 @ 01:51:33
In this lesson, we are going to change the Recovery model from FULL to simple.
This helps if you need to change the model but cannot change it in the database properties | Options tab

Right-click on the database and choose [New Query]
Paste the following code and then click [Execute]

USE MASTER
declare
    @isql varchar(2000),
    @dbname varchar(64)
    declare c1 cursor for select name from master..sysdatabases where name not in ('master','model','msdb','tempdb')
    open c1
    fetch next from c1 into @dbname
    While fetch_status <> -1
        begin
        select @isql = 'ALTER DATABASE @dbname SET AUTO_CLOSE OFF'
        select @isql = replace(@isql,'@dbname',@dbname)
        print @isql
        exec(@isql)
        select @isql = 'ALTER DATABASE @dbname SET RECOVERY SIMPLE'
        select @isql = replace(@isql,'@dbname',@dbname)
        print @isql
        exec(@isql)
        select @isql='USE @dbname checkpoint'
        select @isql = replace(@isql,'@dbname',@dbname)
        print @isql
        exec(@isql)
        fetch next from c1 into @dbname
        end
    close c1
    deallocate c1