T-SQL script to convert all user DBs recovery model

Hello,

Does anyone have a t-sql script to convert all user databases recovery model? ( either way, Simple2Full or Full2Simple )
There is an article but it requires multiple execution of the script.
I wonder if there is a script that can achieve this at one shot.

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=105646

Thank you for your help.
JOSHUABTAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jogosCommented:
How much times you will execute that?  Is it worth it?
Changing recovery model normaly is also followed with a full backup or your going to FULL followed by a trn backup will let this fail.....

But for the challenge try sp_MSForEachDB , use ? for the db_name. Not tested and also no test integrated on the current recovery model .

GO
declare @cmd1 ad nvarchar(1000)
set @cmd1 =
'IF '?' not in  NOT IN(''master'',''tempdb'',''msdb'',''model'')
BEGIN
 ALTER DATABASE ? SET RECOVERY SIMPLE
END 
'
exec sp_msforeachdb @command1 = @cmd1
GO

Open in new window


0
JOSHUABTAuthor Commented:
Thank you for your help.
It worked with a minor error. Even though it's excluded, it still gives an error message on 'tempdb'. To avoid the error, I had to use EXEC function as described below :

http://consultingblogs.emc.com/jamesrowlandjones/archive/2008/07/15/sql-server-database-recovery-model-how-do-you-set-yours.aspx
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.