SQL Server 2005 and SQL Server 2008 are used when the database is already built in db. Bak file restore, error occurs: "The backup set holds a backup of a database other than the existing" check the online method:
method one [not verified]
[SQL] View plaincopy-Returns a result set consisting of a list of databases and log files contained in the backup set.
--Main access to logical file names
- --Returns a result set consisting of a list of databases and log files contained in the backup set.
- --Main access to logical file names
- Use master
- RESTORE filelistonly
- From DISK = ' G:\back. Bak '
- Go
- --**********************************
- /*
- Recover database with Bak, Force restore (REPLACE)
- STATS = 10 shows one record per completion 10%
- Dbtest and Dbtest_log are above g:\back. The logical file in 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 = ten, REPLACE
- GO
- -------------------------------------
- /*
- Back up the data db to the. bak file. This bak file is then used to recover a new database 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
- ---******************************
Method two [ verified, not ] need to note two points: in the "Options" Interface 1. Select Overwrite existing database 2. Modify the "restore to" location in the "Restore Database files to" area, consistent with the actual location of the database to be recovered
Method three [ verified, feasible ] 1. First delete the database that needs to be restored, right-click "Database" under "Server", select "Restore Files and Filegroups", type the new target database name, 2. In "Options", select Overwrite database; 3. Execution is OK.