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

SQL Server 备份和还原数据库

时间:2015-05-28 19:41:12      阅读:272      评论:0      收藏:0      [点我收藏+]

标签:

备份:

--完整备份
declare @db_name varchar(100)
set @db_name = WSS_Content_Test;
declare @db_location varchar(100)
set @db_location = D:\spbr0002\0000000B.bak; --保证有此文件夹
 
backup database WSS_Content_Test
to disk = @db_location
with name = @db_name,stats=5,noinit,noskip,noformat,norewind;

--差异备份
--with name = @db_name,stats=5,noinit,noskip,noformat,norewind,differential;

 

还原:

declare @db_name varchar(100)
set @db_name = WSS_Content_Test;
declare @db_location varchar(100)
set @db_location = D:\spbr0002\0000000B.bak; --保证有此文件夹
 
if exists(select * from master..sysdatabases where has_dbAccess(name)=1 and name=@db_name)
begin
    alter database WSS_Content_Test
    set single_user with rollback immediate
end
restore database WSS_Content_Test
from disk = @db_location
with stats=5,file=1,replace,norewind,nounload,recovery;

 

SQL Server 备份和还原数据库

标签:

原文地址:http://www.cnblogs.com/huangjianwu/p/4536491.html

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