MCITP

MCITP

Tuesday, September 11, 2012

How to set recovery model of all database to simple by using TSQL

Run the below command on master database and it will change the recovery model of all the databases in SQL SERVER to simple.


DECLARE @command varchar(1000)

SELECT @command = 'IF ''?'' NOT IN(''master'', ''msdb'', ''tempdb'')
BEGIN USE ? EXEC(''ALTER DATABASE ? set recovery simple  '') END '

EXEC sp_MSforeachdb @command

For changing the recovery model to FULL use the below command.

DECLARE @command varchar(1000)

SELECT @command = 'IF ''?'' NOT IN(''master'', ''msdb'', ''tempdb'')
BEGIN USE ? EXEC(''ALTER DATABASE ? set recovery FULL  '') END '

EXEC sp_MSforeachdb @command

For changing the recovery model to BULK_LOGGED use the below command.

DECLARE @command varchar(1000)

SELECT @command = 'IF ''?'' NOT IN(''master'', ''msdb'', ''tempdb'')
BEGIN USE ? EXEC(''ALTER DATABASE ? set recovery bulk_logged  '') END '

EXEC sp_MSforeachdb @command


No comments:

Post a Comment

Followers