Here is another script that used sp_msforeachdb to change the recovery model for all the databases.
Note: There is a caveat that changing the recovery model is not recommended without thorough knowledge, but here we are only discussing the technical aspect.
Select name,recovery_model_desc From Sys.databases --To avoid/exception on applying the change, you may add your databases in the list. EXEC sp_msforeachdb ' IF ''?'' not in (''tempdb'',''master'',''msdb'',''model'',''Reportserver'',''ReportserverTempDB'') begin exec (''ALTER DATABASE [?] SET RECOVERY SIMPLE;'') end ' Select name,recovery_model_desc From Sys.databases
You may be interested to know more on sp_MSforeachdb usage, please visit the below links
3 thoughts on “sp_msforeachdb: Changing recovery model for all databases”
Can you also tell me is there anyway to shrink all log files using above method?
First off, Thank you for reading the post.
I find this question very interesting and please find the answer in the below post.