首页 > 数据库 > SQL Server > 正文

SQL Server 备份和还原数据库

2024-08-31 00:54:24
字体:
来源:转载
供稿:网友
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_Testto disk = @db_locationwith 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 immediateendrestore database WSS_Content_Testfrom disk = @db_locationwith stats=5,file=1,replace,norewind,nounload,recovery;


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表