// SQL Server error reference

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
Error message
The backup set holds a backup of a database other than the existing '%ls' database.

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 SalesDb over a database called SalesDb_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

  1. If you really mean to overwrite the target, use REPLACE, with MOVE so 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';
  2. Or restore to a new database name that doesn't exist yet, which needs no REPLACE.

  3. Double-check the target first: REPLACE discards everything in it.

Related errors

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.

// fewer errors, faster fixes

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.