在sqlServer20005 的management studio里使用bak文件还原数据库的时候,总是失败!
Restore failed for Server 'ADANDELI'. (Microsoft.SqlServer.Smo)
An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo
The backup set holds a backup of a database other than the existing 'AAA' database.
RESTORE DATABASE is terminating abnormally. (Microsoft SQL Server,错误: 3154)
解决方法一:
--返回由备份集内包含的数据库和日志文件列表组成的结果集。
--主要获得逻辑文件名
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.修改【将数据库文件还原为】区域里的【还原为】的位置,和要恢复的数据库的实际位置保持一致