Tuesday 17 September 2013

Changing the Recovery model to SIMPLE for multiple database in a single Query: MSSQL Server

If you executed the below query then you will get the output of another query which you need to execute to change the Recovery model from Full to Simple.

Query:
set nocount on go select 'ALTER DATABASE [' + name + '] SET RECOVERY SIMPLE' from sys.databases where database_id > 6 and recovery_model_desc = 'FULL'

Output:
ALTER DATABASE [DB1] SET RECOVERY SIMPLE
ALTER DATABASE [DB3] SET RECOVERY SIMPLE
ALTER DATABASE [DB6] SET RECOVERY SIMPLE
ALTER DATABASE [DB7] SET RECOVERY SIMPLE
ALTER DATABASE [DB9] SET RECOVERY SIMPLE


Note:  The SQL Server have around 15 database and the DB 1,3,6,7,9 only running in Full recovery model. So that you will got the above output copy it and executed like the below.

Query:
Use Master
ALTER DATABASE [DB1] SET RECOVERY SIMPLE
ALTER DATABASE [DB3] SET RECOVERY SIMPLE
ALTER DATABASE [DB6] SET RECOVERY SIMPLE
ALTER DATABASE [DB7] SET RECOVERY SIMPLE
ALTER DATABASE [DB9] SET RECOVERY SIMPLE

Once the above executed successfully please cross verify it randomly by manual check. Now all the database in the SQL server will set to Simple recovery model.

Note:
If the recovery model is in Simple mode then you can't recover the database fully.

Thanks!!!

No comments:

Post a Comment

Rescan Disk Option Greyed Out | New Disks Not visible on Disk management | Update-HostStorageCache

  Recently I have added several LUN from NetApp Storage to Hyper-V servers. But in the disk management I couldn't see those new LUN. Exi...