(Sql Server高级技巧)使用SQL语句实现备份与还原

(1)
backup   database   BBS    
        to   disk   =   'c:/northwind.bak'
--filelistonly查看备份文件信息
  restore   filelistonly    
        from   disk   =   'c:/northwind2.bak'
  restore   database   BBS1    
        from   disk   =   'c:/northwind2.bak'
        with   move   'BBS_Data'   to   'C:/BBS1.mdf', --第一次加载往往

需要move指定新建的位置,否则后面的运行出错
        move   'BBS_Log'   to   'C:/BBS1.ldf'
  go 


(2)
restore database BBSkangco
from disk = 'C:/BBSkangco.bak'
with NORECOVERY --须先指定NORECOVERY
restore LOG BBSkangco
from disk = 'C:/BBSkangco.bak'
--with recovery
with stopat='2007-05-23 17:38:40'--还原的时间点

(3)
backup database BBSkangco to disk='c:/aa.bak' with init
--如果介质为空,SKIP 和 INIT 与 BACKUP 或 DUMP 语句的 FORMAT 子句作用相

同,写新介质头。如果介质不为空,则 SKIP 和 INIT 不写新介质头。
backup log BBSkangco to disk='c:/aa_log.bak' with init
restore database sbxz from disk='c:/aa.bak' with replace,norecovery
restore log sbxz from disk='c:/aa_log.bak' with recovery,stopat='2006-

03-01 20:19:00'


(4)
实例:根据还原时间点来还原资料库
   
  declare   @stopat_time   datetime  
  declare   @str_sql   varchar(4000)  
  set   @stopat_time='2005-04-13'  
  set   @str_sql='restore   log   数据库名称  
        from   日志备份  
        with   recovery,stopat   ='+@stopat_time+''  
  exec   (@str_sql)  
   
  --你也可以把上边的封装成存储过程,这样你可以根据你的需要来还原了. 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值