SQL Server 备份和还原数据库

备份:

--完整备份
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;

 

posted @ 2015-05-28 17:31  KenmuHuang  阅读(351)  评论(0编辑  收藏  举报
如果您看完本篇博文,觉得对您有所收获,请点击右下角的 [推荐]
如果您想转载,请注明出处(原创内容,请尊重个人劳动成果)
如果您有任何意见或建议,欢迎留言
感谢您的阅读,敬请关注我的后续博客文章