sql server2008R2 备份所有数据库

create proc backup_db @targetPath nvarchar(50)
as
set nocount on 
if @targetPath=''
	return ;
declare @sql nvarchar(max)
set @targetPath=@targetPath+case when RIGHT(@targetPath,1)='\' then '' else '\' end
set @sql=''

select @sql=@sql+'backup database ['+name+'] to disk='''+@targetPath+name+'.bak'' '+CHAR(10)
from sys.databases 
where name not in('master','tempdb','model','msdb')
--print @sql
exec (@sql)

go


 

你可能感兴趣的:(sql server2008R2 备份所有数据库)