SQL Server error 3154: Backup set is of a different database
RESTORE is overwriting an existing database with a backup of a different database. Add WITH REPLACE if that's intended, or restore under a new name.
- Error number
3154- Severity
- 16
- Category
- Backup and restore
What it means
As a safety check, SQL Server refuses to restore over an existing database when the backup came from a different database (a different name or database GUID). This protects you from overwriting the wrong database by mistake. Error 3013 follows it.
Common causes
- Restoring a backup of
SalesDbover a database calledSalesDb_Test, or over a database of the same name that was created separately. - Refreshing a test copy from production without
REPLACE.
How to fix it
-
If you really mean to overwrite the target, use
REPLACE, withMOVEso the files don't collide with the source database's files.RESTORE DATABASE SalesDb_Test FROM DISK = N'D:\Backup\SalesDb.bak' WITH REPLACE, MOVE N'SalesDb' TO N'D:\Data\SalesDb_Test.mdf', MOVE N'SalesDb_log' TO N'D:\Data\SalesDb_Test_log.ldf'; -
Or restore to a new database name that doesn't exist yet, which needs no
REPLACE. -
Double-check the target first:
REPLACEdiscards everything in it.
Related errors
3013BACKUP or RESTORE ended abnormally3101Exclusive access could not be obtained5120Unable to open the physical file
More backup and restore errors
The code and message text are from the Microsoft Database Engine events and errors reference. Browse the full SQL Server error list or search every database error.
Work on SQL Server in SQLly
A native SQL client for macOS, Windows and Linux with schema-aware IntelliSense, guardrails for risky statements and clear error messages, for SQL Server and the other databases you use.