首页 > 代码库 > 数据库作业通用代码

数据库作业通用代码

 1 declare @backup nvarchar(500) 2 declare @file nvarchar(500) 3 declare @DeleteFile nvarchar(500) 4 declare datebak cursor for 5 select [bak]=backup database  +quotename(Name)+  to disk =‘‘F:\DabaBaseBackup\BU2\+Name+\+Name+_+convert(varchar(8),getdate(),112)+.bak‘‘  with init,[file]=master.dbo.xp_create_subdir N‘‘F:\DabaBaseBackup\BU2\+Name+‘‘‘‘ 6 ,[DeleteFile]=master.dbo.xp_delete_file 0,N‘‘F:\DabaBaseBackup\BU2\+Name+‘‘‘,N‘‘bak‘‘,N‘‘‘+convert(varchar(100),DateAdd(Day,-10,GETDATE()),126)+‘‘‘‘ 7 from master..sysdatabases  where Name like KR_% 8 open datebak 9 fetch next from datebak into @backup,@file,@DeleteFile10 while @@fetch_status=011     begin12         EXECUTE (@DeleteFile)13         EXECUTE (@file)14         EXECUTE (@backup)15         fetch next from datebak into @backup,@file,@DeleteFile16     end17 close datebak18 deallocate datebak19 GO

 

数据库作业通用代码