sqlserver 自动备份所有数据库的SQL

前端之家收集整理的这篇文章主要介绍了sqlserver 自动备份所有数据库的SQL前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

<div class="codetitle"><a style="CURSOR: pointer" data="3573" class="copybut" id="copybut3573" onclick="doCopy('code3573')"> 代码如下:

<div class="codebody" id="code3573">
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

原文链接:https://www.f2er.com/mssql/64208.html

猜你在找的MsSQL相关文章