sqlserver 主動備份一切數據庫的SQL。本站提示廣大學習愛好者:(sqlserver 主動備份一切數據庫的SQL)文章只能為提供參考,不一定能成為您想要的結果。以下是sqlserver 主動備份一切數據庫的SQL正文
use master
declare @DbName varchar(60)
declare @BackSql varchar(1000)
declare myCursor cursor for
SELECT [name] FROM SYSDATABASES
where [name] not in ('master','model','msdb','tempdb')
order by [name]
open myCursor
fetch next from myCursor into @DbName
while(@@FETCH_STATUS = 0)
begin
if datename(weekday, getdate())='禮拜三' --每周三籠罩上周三的
begin
select @BackSql='Backup DATABASE ['+@DbName+'] to disk=''E:\DbBackUp\'+@DbName+'禮拜三.bak'' with format'
end
else--天天籠罩上一天的
begin
select @BackSql='Backup DATABASE ['+@DbName+'] to disk=''E:\DbBackUp\'+@DbName+'AutoBack.bak'' with format'
end
exec(@BackSql)
fetch next from myCursor into @DbName
end
close myCursor
DEALLOCATE myCursor