码迷,mamicode.com
首页 > 数据库 > 详细

数据库作业通用代码

时间:2014-11-17 17:20:10      阅读:196      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   ar   os   sp   for   数据   div   

 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,@DeleteFile
10 while @@fetch_status=0
11     begin
12         EXECUTE (@DeleteFile)
13         EXECUTE (@file)
14         EXECUTE (@backup)
15         fetch next from datebak into @backup,@file,@DeleteFile
16     end
17 close datebak
18 deallocate datebak
19 GO

 

数据库作业通用代码

标签:style   blog   color   ar   os   sp   for   数据   div   

原文地址:http://www.cnblogs.com/doNetTom/p/4103705.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!