SQL SERVER恢复数据错误解决:The backup set holds a backup of a database other than the existing

http://dba.stackexchange.com/questions/44967/error-3154-while-restoring-a-backup-using-with-replace

You should use WITH REPLACE and in general avoid using the point-and-click thingies in Management Studio - they're inflexible and often have bugs.

This worked for me:

USE [master];
GO

CREATE DATABASE test;
GO

CREATE DATABASE test2;
GO

BACKUP DATABASE test TO DISK = 'c:\temp\test.bak' WITH INIT, COMPRESSION;
GO

RESTORE DATABASE test2
  FROM DISK = 'c:\temp\test.bak'
  WITH REPLACE,
  MOVE 'test' TO 'c:\temp\test2.mdf',
  MOVE 'test_log' TO 'c:\temp\test2.ldf';

Also you should make sure when you backup databases you use WITH INIT and/or don't point the device at a file that already contains a backup (since it might not be the same database you're backing up now - especially if you reuse names like test...).

1) Use WITH REPLACE while using the RESTORE command.

2) DROP the older database which is conflicting and restore again using RESTORE command.

There is no problem with the SQL Server version. As Aaron pointed out, I am also able to restore the database from 2008 to 2012 and same versions as well.


http://blog.sqlauthority.com/2013/11/23/sql-server-fix-error-3154-the-backup-set-holds-a-backup-of-a-database-other-than-the-existing-database-ssms/


http://blog.csdn.net/j2eevic/article/details/7408432

方法一:

--返回由备份集内包含的数据库和日志文件列表组成的结果集。
--主要获得逻辑文件名
USE master
RESTORE FILELISTONLY
   FROM DISK = 'g:\back.Bak' 
Go
--**********************************
/*
利用bak恢复数据库,强制还原(REPLACE)
STATS = 10 每完成10%显示一条记录
DBTest和DBTest_log是上面g:\back.Bak里的逻辑文件
*/
USE master
RESTORE DATABASE DB 
   FROM DISK = 'g:\back.Bak'
   WITH MOVE 'DBTest' TO 'E:\Program Files\Microsoft SQL Server2005\Data\DB.mdf', 
   MOVE 'DBTest_log' TO 'E:\Program Files\Microsoft SQL Server2005\Data\DB_log.ldf',
STATS = 10, REPLACE
GO
-------------------------------------

/*
备份数据DB 到.bak文件。然后利用此bak文件恢复一个新的数据库DBTest。
*/
USE master
BACKUP DATABASE DB 
  TO DISK = 'g:\DBBack0930.bak' 
RESTORE FILELISTONLY 
  FROM DISK = 'g:\DBBack0930.bak' 
RESTORE DATABASE DBTest 
  FROM DISK = 'g:\DBBack0930.bak' 
  WITH MOVE 'DBTest' TO 'E:\Program Files\Microsoft SQL Server2005\Data\DBTest.mdf', 
  MOVE 'DBTest_log' TO 'E:\Program Files\Microsoft SQL Server2005\Data\DBTest_log.ldf'
GO 
---******************************

方法二
需要注意两点:
在【选项】界面里
1.选择“覆盖现有数据库”
2.修改【将数据库文件还原为】区域里的【还原为】的位置,和要恢复的数据库的实际位置保持一致

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值