--Смена модели восстановления у всех баз
DECLARE @MODEL NVARCHAR(3000) = 'FULL' -- МОДЕЛЬ ТЕКУЩАЯ
DECLARE @MODELNEW NVARCHAR(3000) = 'SIMPLE' -- МОДЕЛЬ НОВАЯ
DECLARE @DBNAME NVARCHAR(150) = ''
DECLARE @EXECSTR NVARCHAR(3000) = ''
USE
TEMPDB
IF
EXISTS(SELECT
[TABLE_NAME] FROM [INFORMATION_SCHEMA].[TABLES]
WHERE [TABLE_NAME]
=
'T1forChangeModel')
BEGIN
DROP
TABLE T1forChangeModel
END
--
Temp table with databases for changes.
SELECT
IDENTITY(INT,
1,1)
AS ID
,DB.*
INTO
T1forChangeModel
FROM
SYS.DATABASES
AS DB
WHERE
lower(DB.NAME)
NOT
IN
('master',
'tempdb',
'model',
'msdb')
AND
UPPER(DB.state_desc)
=
'ONLINE'
AND
UPPER(DB.recovery_model_desc)
= @MODEL
--
Change for every row (db name).
DECLARE
@X INT
= 0
DECLARE
@COUNTF INT
=
(SELECT
COUNT(*)
FROM T1forChangeModel)
WHILE
(@X
< @COUNTF)
BEGIN
SET
@X = @X
+ 1
SET
@DBNAME =
(SELECT
TOP 1 F.NAME
FROM T1forChangeModel
AS F
WHERE F.ID
= @X)
SET
@EXECSTR =
'USE [MASTER]; '
+
'ALTER DATABASE ['
+ @DBNAME
+
'] SET RECOVERY '
+ @MODELNEW
PRINT
@EXECSTR
EXECUTE(@EXECSTR)
END
DROP TABLE T1forChangeModel
Комментариев нет:
Отправить комментарий