复制代码代码如下:usemasterdeclare@DbNamevarchar(60)declare@BackSqlvarchar(1000)declaremyCursorcursorforSELECT[name]FROMSYSDATABASESwhere[name]notin('master','model','msdb','tempdb')orderby[name]openmyCursorfetchnextfrommyCursorinto@DbNamewhile(@@FETCH_STATUS=0)beginifdatename(weekday,getdate())='星期三'--每周三覆盖上周三的beginselect@BackSql='BackupDATABASE['+@DbName+']todisk=''E:DbBackUp'+@DbName+'星期三.bak''withformat'endelse--每天覆盖上一天的beginselect@BackSql='BackupDATABASE['+@DbName+']todisk=''E:DbBackUp'+@DbName+'Aut
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
标签: sqlserver 自动 备份 所有 数据库 SQL
声明:本文内容来源自网络,文字、图片等素材版权属于原作者,平台转载素材出于传递更多信息,文章内容仅供参考与学习,切勿作为商业目的使用。如果侵害了您的合法权益,请您及时与我们联系,我们会在第一时间进行处理!我们尊重版权,也致力于保护版权,站搜网感谢您的分享!