Passage des bases SQL en mode simple
Une procédure SQL qui va permettre de passer toutes les bases de données d'une instance en mode SIMPLE et réduire les logs de ces bases.
DECLARE @NAME_DB varchar(255)
DECLARE @SQL nvarchar(255)
DECLARE Curs CURSOR FOR
SELECT [name] FROM [master].[sys].[databases] WHERE (database_id > 6 AND state_desc !='OFFLINE')
OPEN Curs
FETCH NEXT FROM Curs
INTO @NAME_DB
WHILE @@FETCH_STATUS = 0
BEGIN
--PRINT(@NAME_DB)
EXEC('USE [' + @NAME_DB + '];'
+'ALTER DATABASE [' + @NAME_DB + '] SET RECOVERY SIMPLE;'
+'')
EXEC('USE [' + @NAME_DB + '];'
+'DECLARE @FILE_NAME varchar(255)'
+'SET @FILE_NAME = (SELECT name FROM ['+@NAME_DB+'].[sys].[database_files] WHERE type = 1)'
+'DBCC SHRINKFILE (@FILE_NAME, 1);'
)
FETCH NEXT FROM Curs
INTO @NAME_DB
END
CLOSE Curs
DEALLOCATE Curs