Generate Restoration Script For Multiple Databases 1709698444
Generate Restoration Script For Multiple Databases 1709698444
Generate Restoration Script For Multiple Databases 1709698444
www.linkedin.com/in/srinivas-merugu-dba-azure
SELECT 'Alter database ['+ name+'] set Single_User with rollback immediate;'+
e. Script will generate restoration script for all Database except system Databases.
f. If need to generate restoration script for specific databases then mention database name
in last line code.
WHERE d.name in ('DBName1’,’DBName2’,………) --LIKE '%DatabaseName%'
Use master
go
DECLARE @date CHAR(8)
SET @date = (SELECT CONVERT(char(8), GETDATE(), 112))
SELECT 'Alter database ['+ name+'] set Single_User with rollback immediate;'+
Srinivas Merugu
www.linkedin.com/in/srinivas-merugu-dba-azure
' RESTORE DATABASE ['+ name + '] FROM DISK = ''' + @path + '' + name + '.bak'' WITH FILE
= 1 '+movecmdCTE.MoveCmd
+', RECOVERY, REPLACE, STATS=5,buffercount=600;'+
'Alter database ['+ name+'] set Multi_User ;'
FROM sys.databases d
INNER JOIN MoveCMDCTE ON d.name = movecmdcte.databasename
WHERE d.name not in ('master','model','msdb','tempdb','distribution') --LIKE
'%DatabaseName%'
GO