指针


 use master 

go
declare @DbName nvarchar(1000
declare @BackupSQL nvarchar(1000
declare @time nvarchar(12)
set   @time= left(replace(replacereplace(CONVERT(varchargetdate(), 120 ),'-','')  ,' ',''),':',''),12)
select @time 

declare Cursor_DBname cursor for 
    SELECT [name] FROM master..SYSDATABASES
    where [name]   in ('MRP_WRSDB','MRP_YHMES','ReportServer','ReportServerTempDB','MRP_ERPDBTEST')
    order by [name] 

open Cursor_DBname 
fetch next from Cursor_DBname into @DbName 
while(@@FETCH_STATUS = 0
begin 
    select @BackupSQL='Backup DATABASE ['+@DbName+'] to disk=''L:ERP_DB_Daily_BackupDB_1357'+@DbName+'.bak'' with format,COMPRESSION'
    exec(@BackupSQL
    fetch next from Cursor_DBname into @DbName 
end 
close Cursor_DBname 

DEALLOCATE Cursor_DBname
原文地址:https://www.cnblogs.com/Snowfun/p/3600411.html