咨询热线:4006-75-4006
售前:9:00-23:30 备案:9:00-18:00 技术:7*24h
SQL Server 批量完整备? 实现方式二 使用拼凑SQL的方式
DECLARE @SQL VARchar(MAX) select @SQL = COALESCE(@SQL,'') + ' BACKUP DATABASE '+ QUOTENAME(name,'[]') + ' TO DISK = ''E:DBBackup'+ name + '_' + CONVERT(char(8),GETDATE(),112) + CAST(DATEPART(hh, GETDATE()) AS VARCHAR) + CAST(DATEPART(mi, GETDATE()) AS VARCHAR) + '.bak' + ''' WITH NOINIT, NOUNLOAD, NAME = N''' + name + '_backup'', NOSKIP, STATS = 10, NOFORMAT' from sys.databases where database_id>4 AND name like '%%' AND state =0 PRINT(@SQL) EXECUTE(@SQL)
生成的脚本如Figure2所示,如果想脚本更加美观,可以加上GO语句,如Figure2所?:
(Figure1:生成的T-SQL脚本)
(Figure2:生成的T-SQL脚本)