Our Jr. DBA ran to me with this error just a few days ago while restoring the database.
Error 3154: The backup set holds a backup of a database other than the existing database.
Solution is very simple and not as difficult as he was thinking. He was trying to restore the database on another existing active database.
Fix/WorkAround/Solution:
1) Use WITH REPLACE while using the RESTORE command. View Example
2) Delete the older database which is conflicting and restore again using RESTORE command.
I understand my solution is little different than BOL but I use it to fix my database issue successfully.
3) Sample Example :
RESTORE DATABASE AdventureWorks
FROM DISK = 'C:\BackupAdventureworks.bak'
WITH REPLACE
Reference : Pinal Dave (http://blog.SQLAuthority.com)




This was a huge help.
But I think you forgot the slash in the example
FROM DISK = ‘C:\
(it didn’t work for me until I added the slash.)
Anyways, thanks a lot, you saved me from having to go to my senior dba
Charming little piece of code!! thanks!
great!
Great! thanks.
check the ‘Restore on Existing Database’ option box if you are using the GUI
Nice post. Could have stopped our Go live ! Thanks a lot.
Good for you man!!!!! A question: Why it did not work when I tried to do it through the RESTORE option available in Microsoft SQL 2005? The script generates “WITH FILE = 1, NOUNLOAD, STATS = 10″ instead of “WITH REPLACE”. Did I miss anything in the set up?
Thanks man, I was trying to restoring using the wizard, but it work beautifully, with your code
Thanks for this. Seems small to one who knows but I had some pain trying to restore a db until I found this. Thanks
This helps me a lot!
Great! it helped!
you just saved my life! Thanks!!!
Thankyou so much !! gr8 help
Thank you so much, it worked great
You can also go to the options page of the Restore Data Base dialog (In Management Studio Express) and select the option, Overwrite Existing Database.
Pinal you are great!!!!!
Three cheers for Pinal….right from my heart…..
Thank you very much….
Hi Pinal,
Thank you very much…
It’s working fine….
Simply super coding…
Great article, especiall full example with MOVE. BTW, is there some workaround in order not to use all the files-to-move? In my case there was 5 files or so. Is there some way to point all of them to some default location?
Thanks alot man, helped me a lot :)
I have tried to use the GUI, and the ‘Restore on Existing Database’ option, but I still get the error.
Thank You very much. This article helped at right time
you are a genius, problem SOLVED !
Thanks a lot for this post. People using the GUI should tick the following option: “Overwrite the existing database”. (SQL Server Management Studio Express)
Thanks a lot for the Article. It saved a hell lot of time.
thanks a lot…
really helpful!!! thanks a lot…
A lot a thank!!
THANK YOU VERY MUCH PINAL
U SOLVED MY PROBLEM IN A MATTER OF SECS
U r the TOUGHEST person in SQL SERVER
You are the man!!!!!!!!!!
thanks a lot..
Great piece of code. Was almost convinced that MS had put a restriction in there…
Nice!
Thanks a lot…!!!!
Thanks a lot ……………..
Thanks…developers aren’t DBA’s…saved my rear!
tsss, amazing what this little query can do :) saved me a phonecall and alot of time, thanks alot :)
Excellent!! …. thanks Pinal!
Thanks a lot…It was a magical code..
Thanks a lot! I could do it from the GUI of SQL Mgt.. but this worked just great!
Thanks a lot! I coudnt do it using GUI but this didit!
Hi..
This really helped me!!!! Thank you soo much!!!!
hi…
Thank u very much…. :)
Thank you!!!
Many thanks for your help :)
Great, saved hours of recreating the database table by table again, and also i said “oh, hope i knew that before, and didn’t waste …..”
Thank you :)
Fantastic ! Thanks a ton !!!
– Juwel
If you are using the wizard you can achieve exactly the same by clicking the radio button that says “restore over the existing database” (or similar) it’s the top option on the options bit … but nobody’s gonna read my comment it’s too low on the page!
Great. It worked for me Thanks
great work man,
It simplifies my search
Hi Pinal Dave,
And thanks Pinal Dave too much you know why . b/c when ever i have problem with sql server query i search in your site and i got the rite solution :) .
i m happy to see you when ever i see your site.
i have RESTORE DB in sql server 2000 so i use your this solution.
RESTORE DATABASE AdventureWorks
FROM DISK = ‘C:\BackupAdventureworks.bak’
WITH REPLACE
it is very halp full for me Thanks again Dave :)
ok
Take care
bye bye
Thanks man its a good code
hi,
thanks for the response.
right now i am searching for sql dba openings.
can any body help me the important and frequent interview questions on core sql dba.
thanks
great thanks , and i wasn’t expect this solution will be solve my problem.
Great Idea, but if I want to restore without replacing the existing database ?? I want to insert tables inside the backup file to be added to the tables already there in the existing database !!
Any help ?
Many thanks Pinal, good things always comes in small packages…this query solved my problem…cheers:)
It Worked ! Thanks :D
Worked like a charm! Thanks!
These 2 lines of codes save my lots times, whenever i goes to restore dayabase i always face this problem … I search problem on google and always yout these lines works ,.
Thanks a ton
Thanks a lot!
great code. huge thanks!
hey thanks for the great tip! was a big help — jp
Thanks a bunch for the tip!
Hi Pinal,
I took a full back-up from a server and tried to restore it on another server by creating a new database.
Since it was a full-back up, I had three files
abc.mdf
abc_log.ldf
sysft_abcCatalog
When I try to restore, the other machine did not have full-text installed. Thus I went for partial restore with replace option enable…. but the replace does not work.
I get the error Error 3154: The backup set holds a backup of a database other than the existing database. ….. even through I have written REPLACE option in the restore query:
Below is my query:
RESTORE DATABASE XYZ
FROM DISK = ‘C:\nusrath\abc.bak’
WITH REPLACE,
FILE=1,
PARTIAL,
MOVE ‘abc’ TO ‘c:\DATA\XYZ.mdf’,
MOVE ‘abc_log’ TO ‘c:\DATA\XYZ_log.ldf’,
NOUNLOAD,
STATS = 10
How should I work around ? Please help.
Thanks,
Nusrath
I was just able to migrate a 2000 sql database to a 2008 with this little tidbit.
THANX!
H! Pinal , thanks a lot .i tried da way u suggested . i am able to create database from my backup file . but still getting db blank with no tables . i am using ms-sql 2005 server.
could any one suggest me whats the issue i m facing .
i am doin like”RESTORE DATABASE RelinkDB
FROM DISK = ‘C:\Program Files\Microsoft SQL Server\MSSQL.2\MSSQL\Backup\RelinkDB.bak’
WITH REPLACE”
Thanks mate. Your post was quite useful.
Great hint. Cheers!
THanxxxxxxxxxxxxxxxxxxxx a lot!
Thank you!!!!! I don’t think i’ve ever had an issue resolved so fast and simply!!!
Thanks for this, I was having the same problem, but that has fixed it!
Thank you. That was a big help.
Dax
Great Article! It helped us a lot. Thank you very much!
Thanks Man! :D
This is really a great work around and it resolved the issue.
Thanks a lot Pinal
Thanks for the tip, Pinal. I’ve had to use it on several occasions.
Hello Nusrath
I had exactly the same issue. It seems to happend when we make a backup of several databases appendes on a same bak fIle.
In my case I had one backup file named J04Vendredi.BAK on which where 4 databases backup
1-master
2-msdb
3-lienWinXS
4-aeosdb
I wanted to restore aeosdb on a database called aeosdbLFSB on the target server located physically ON
C:\Data\aeosdbLFSB.mdf’,
C:\Data\aeosdbLFSB_log.ldf’,
After 2 hours of unsuccessfull tries, searches on the net, in the doc and a lot of dirty words I got it that way:
You have to know what was the name of the logical file on the source server with
RESTORE FILELISTONLY
FROM disk = ‘C:\LFSBVM002\J04Vendredi.BAK’ (replace with your path and filename
WITH file = 4
(You have to specify the sequence number where is the wished database !!!)
The first colum showed the logical names of the source server
-aeosdb_dat
-aeosdb_log
Then, I had to write the SQL statement below
RESTORE DATABASE aeosdbLFSB
FROM DISK = ‘C:\LFSBVM002\J04Vendredi.BAK’
WITH
REPLACE,
MOVE ‘aeosdb_dat’ TO ‘C:\Data\aeosdbLFSB.mdf’,
MOVE ‘aeosdb_log’ TO ‘C:\Data\aeosdbLFSB_log.ldf’,
FILE=4
Thank you very much!
Thanks alot!!! Your code very useful…
Thanks a lot. Worked in minutes !!
You saved me a lot of time. Thanks!!!
cool, solve my issue:
RESTORE DATABASE AdventureWorks
FROM DISK = ‘C:\BackupAdventureworks.bak’
WITH REPLACE
Thanks… I restored the database correctly… Once again thanks…
Thanks Alot!
Really Greate and Wonderful
Hi,
For developing/testing purposes with original data I need to restore / copy data from one database to another with same database structure (tables, SPs, views, etc) but a different database name. from a backup file from original.
What is the best approach for this? CAn I use the restore command for this?
Thanks for the article…
Have a nice day.
It worked!!
Thanks
U DA MAN
Thanks Pinal. You have very good common sense in programming. Now let’s see what cool chakra graphic I get!
Hi, I got a question…I backuped my database from an Win2003 Server English Edition and when I try to restore the database into my development enviorment (wich is an XP Professional Spanish Edition) it shows an error like this:
Mens. 5133, Nivel 16, Estado 1, LÃnea 1
Directory lookup for the file “C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\MyDataBase.mdf” failed with the operating system error 3(El sistema no puede hallar la ruta especificada.).
Mens. 3156, Nivel 16, Estado 3, LÃnea 1
Of course I dont Have “Program Files”, in spanish it is called “Archivos de Programa” I dont how I can change that..hope you can help me…Thanks..
(by the way, El sistema no puede hallar la ruta especificada. = The system could not find the specified path.)
hai,
i tried many time to restore backup file through GUI restore.
i wasn’t able to restore.
i tried your query within second finished.
Many Thanks,
Bala
Thank you so much, your solution worked for me!!
thanks a lot, this was the my problem.
this solved my problem..
thank a lot
Great!!! Works like a charm :)
Sorry, it doesnt work for me please help…
Thank you very much for your simple example. It works
Another individual happy to have stumbled upon your post. Thanks for sharing.
Thank you sir! I can go to bed now!!
Thanks a lot. It work !!!!!!!!!!!
Thanks a lot for this is very helpful
You’re the king man, a great piece of code that helped me a lot. Thanks kindly
thnx
Excellent! Thanks.
Magic…..
thank you pinal
the simple code was easy to use and it worked like a charm
thanks
WOW, you saved a life out there somewhere in Atlanta man…. I was dead before this.. you win two internets!
Thanks. This tip should be on the main page of Microsoft SQL Server issues?
Why isn’t it there yet?
Thank you very much, you saved my ass.
LOL
hay thanx it really helped me alot
Great Work…… very helpful and efficient technique !!!!!!!
Thank you Thank you!!!
Your my idol!!
Thank you very much! Great Help!
Thanks a bunch cos FIX No 1 solved my problems perfectly.
Is this possible to replace filegroup with restore command with replace
Mate,
That is golden
Nice Work
Super. Worked like magic. Thanks a lot!!!!
Is there a way to delete/drop a database backup from the tape device? Please kindly advise.
thanks.
Thanks Pinal….Keep up this nice work…..cheers
Hi
Thanks for the answer, mate. It was spot on. For newbies like me this was a great help
Cheers, Prad
Saved me a lot of trouble, thanks
Thanks! worked for me!
For SQL2005 do not use ‘WITH REPLACE’ but only ‘REPLACE’ indeed, the word WITH must not be present