DECLARE
@FileName VARCHAR(200),
@CurrentTime VARCHAR(50),
@DBName VARCHAR(100),
@SQL VARCHAR(1000)
SET @CurrentTime = CONVERT(CHAR(8),GETDATE(),112) + CAST(DATEPART(hh, GETDATE()) AS VARCHAR) + CAST(DATEPART(mi, GETDATE()) AS VARCHAR)
DECLARE CurDBName CURSOR FOR
SELECT NAME FROM Master..SysDatabases where dbid>4
OPEN CurDBName
FETCH NEXT FROM CurDBName INTO @DBName
WHILE @@FETCH_STATUS = 0
BEGIN
--Execute Backup
SET @FileName = 'D:\hyf\' + @DBName + '_' + @CurrentTime
SET @SQL = 'BACKUP DATABASE ['+ @DBName +'] TO DISK = ''' + @FileName + '.bak' +
''' WITH NOINIT, NOUNLOAD, NAME = N''' + @DBName + '_backup'', NOSKIP, STATS = 10, NOFORMAT'
EXEC(@SQL)
--Get Next DataBase
FETCH NEXT FROM CurDBName INTO @DBName
END
CLOSE CurDBName
DEALLOCATE CurDBName
相关文章
- 04-04SQL-Server练习题
- 04-04sql注入跨站点脚本编制
- 04-04sql 不同server間寫入數據
- 04-04MS SQL表字段自增相关的脚本
- 04-04VC++数据库操作-像powerbuilder一样写sql脚本
- 04-04SQL Server 视图修改后有错怎么办?
- 04-04java.sql.SQLException: The server time zone value ‘�й���ʱ��’ is unrecognized or represents more tha
- 04-04sql脚本查询日期时间段日期
- 04-04SQL-Server多表关联查询并分页
- 04-04借用pcrcona-xtrbackup做备份恢复演练,附带备份脚本最佳实践-亲试ok-20210114