post

-- First, declare the variable @databasename

declare @databasename varchar(128)

-- Next declare the cursor to contain all databases with the
-- recovery model 1 (which is FULL) but not the systemdatabases

declare dbcursor CURSOR for
select name from master.sys.databases
where name not in ('master','tempdb','model','msdb')
and recovery_model=1

-- Open the cursor and put the databasename in to the @databasename
-- variable.

open dbcursor
fetch next from dbcursor into @databasename
while @@FETCH_STATUS = 0

-- Now run the code to change the database

Begin
alter database @databasename set recovery simple

-- When that is done, get the next name from the cursor until all
-- have been modified

fetch next from dbcursor into @databasename
end

-- Close and deallocate the cursor

close dbcursor
deallocate dbcursor

 

http://www.sqlservercentral.com/Forums/Topic1327362-1550-1.aspx#bm1327380

post