About this article: This article is reviewed against the cited sources. This is source research, not lab validation. Check the stated versions and your own requirements before making changes.
The full message reads The backup set holds a backup of a database other than the existing '<name>' database. SQL Server returns error 3154 when you restore a backup onto a name that already exists on the server and the existing database is not the one the backup came from. The restore stops before it overwrites anything. Fix it by restoring under a different name, by removing an empty database that was created by mistake, or, only after you have proved the existing database can be lost, by adding WITH REPLACE.
The message is a safety check, not a fault in the backup file. The risk lies in the cure: WITH REPLACE switches off this check and several others at once.
What the error means
Microsoft's list of Database Engine events and errors (3000 to 3999) gives error 3154, severity 16, with the text "The backup set holds a backup of a database other than the existing '%ls' database." Microsoft's SSMS restore page quotes the message in its restore example with the name Sales. It appears when the Overwrite option (WITH REPLACE) is not ticked and the target database exists.
Microsoft describes the check in two slightly different ways. The RESTORE arguments page says the safety check stops a restore if two conditions both hold: the database named in the RESTORE statement already exists on the server, and the database name is different from the name recorded in the backup set. The SSMS page and the RESTORE page describe it through the database family GUID: "If the database specified in a RESTORE statement already exists on the current server and the specified database family GUID differs from the database family GUID recorded in the backup set, the database is not restored. This is an important safeguard."
Both descriptions are on Microsoft's pages, so check both values before you decide. The family GUID is documented as the "ID of the original database when created" that "stays the same when the database is restored." Applying the GUID rule, a database that was dropped and created again under the same name has a new family GUID, so a restore onto it would fail the check even though the names match. That is a reading of the GUID rule, not a sentence from Microsoft's pages, and the name-based description above would not stop such a restore. Compare both values in the checks below.
What WITH REPLACE changes is also documented. Microsoft says REPLACE "should be used rarely and only after careful consideration" and lists the checks it overrides:
- Restoring over an existing database with a backup taken of another database.
- Restoring over a full or bulk-logged database where no tail-log backup was taken and STOPAT is not used. Microsoft warns that you "can lose committed work" here.
- Overwriting existing files, including files that belong to a database that is not online.
Microsoft adds that "Undoing the effects of a restore is not possible; however, you can negate the effects of the data copy and rollforward by starting over on a per-file basis."
Likely causes
| Cause | What you see | How to confirm |
|---|---|---|
| Backup of database A restored over database B on the same server | Names differ; error 3154 on the first RESTORE | RESTORE HEADERONLY shows DatabaseName A; target is B |
| An empty database was created first, then restored into by name | A new database of the same name sits on the server with no data | Target database is small or empty; its family GUID differs from the backup's FamilyGUID |
| The target was dropped and created again | Same name, but a different history | Family GUID in sys.database_recovery_status differs from the backup's |
| Wrong backup set picked from a file holding several | The file has more than one set and FILE = 1 holds another database | RESTORE HEADERONLY lists each set with its DatabaseName and Position |
| Database is the right one but the name is re-used for a copy | A test copy and the source share a name across instances | Compare ServerName and DatabaseName in the header with the target |
Prove the cause before changing anything
All of these are read-only. Replace the file path and database name with yours.
Read the backup header. Microsoft documents RESTORE HEADERONLY and the columns DatabaseName, FamilyGUID, BackupType, ServerName and Position.
RESTORE HEADERONLY
FROM DISK = N'D:\Backup\SalesDB_full.bak';
Write down DatabaseName, FamilyGUID and the Position of the set you mean to restore. If the file holds several sets, the FILE = n option on RESTORE picks one by its position; the default is 1. A mismatch between the position you meant and the position you got is the fourth cause in the table.
Read the target. Microsoft documents family_guid in sys.database_recovery_status as the identifier of the backup family for matching restore states.
SELECT DB_NAME(database_id) AS database_name, family_guid
FROM sys.database_recovery_status
WHERE database_id = DB_ID(N'SalesDB');
The family GUID from the header and from the target decide the result:
- They match: the existing database is the same family as the backup, and a plain restore should not return 3154. Re-read the error for another cause.
- They differ and the target holds real data: you are about to overwrite a different database. Stop and use a new name.
- They differ and the target is an empty shell: it was created by hand or by a deployment script. It can be dropped after you confirm nobody uses it.
List what the existing database contains before any decision. Microsoft documents sys.database_files and its size column in 8-KB pages.
SELECT name, type_desc, size * 8 / 1024 AS size_mb
FROM SalesDB.sys.database_files;
Run RESTORE FILELISTONLY on the backup as well to see the logical names and original paths you will meet in a restore to a new name.
Fix
Different database, or you want both copies: restore under a new name. Microsoft documents the MOVE option for relocating files and avoiding collisions with existing files when a database is copied. List the logical names with RESTORE FILELISTONLY, then move each file to a new path.
RESTORE DATABASE [SalesDB_Copy]
FROM DISK = N'D:\Backup\SalesDB_full.bak'
WITH MOVE N'SalesDB' TO N'E:\Data\SalesDB_Copy.mdf',
MOVE N'SalesDB_log' TO N'F:\Log\SalesDB_Copy_log.ldf',
RECOVERY;
Risk: this creates new files and a new database and leaves the existing one untouched, but the new files take disk space equal to the sizes in the backup. Back out by dropping the new database and deleting its files. A wrong MOVE path that points at an existing file is stopped by the same file-overwrite safety, so do not add REPLACE to push it through.
An empty look-alike is in the way. Drop it, then restore. RESTORE can create the database from the backup, as in Microsoft's point-in-time example, which restores into a database that "doesn't currently exist on the server".
DROP DATABASE [SalesDB];
Disruptive step: DROP DATABASE deletes the database and, in Microsoft's words, "deletes the physical disk files used by the database"; if the database or one of its files is offline, the files are left on disk. "A dropped database can be re-created only by restoring a backup", so there is no way back except a backup. Microsoft also says you can't drop a database that is currently in use, meaning one with locks held by any user. Take a backup first if the shell holds anything at all, and confirm with a second person that nothing reads from it.
The existing database must be replaced. Add WITH REPLACE only after the checks above.
RESTORE DATABASE [SalesDB]
FROM DISK = N'D:\Backup\SalesDB_full.bak'
WITH REPLACE, RECOVERY;
Disruptive step: WITH REPLACE deletes the existing database and overwrites its files, and it removes the requirement to take a tail-log backup first. Microsoft says undoing a restore is not possible, and the committed work in the old database since its last log backup is lost. There is no way back unless you took a backup of the existing database before the statement.
If the log of the existing database holds work you need, take a tail-log backup first, with BACKUP LOG ... WITH NORECOVERY.
Disruptive step: a tail-log backup taken WITH NORECOVERY puts the existing database into the restoring state. Microsoft's SSMS page says not unchecking the tail-log option "will result in the existing database, Sales, to change to the restoring state". The database is unavailable to users until it is restored or recovered. To back out before you restore over it, run RESTORE DATABASE [SalesDB] WITH RECOVERY;, which Microsoft shows as the way to bring a restoring database online. Keep the tail-log backup file; it is the only copy of that work.
In SSMS the same choice appears as "Overwrite the existing database (WITH REPLACE)" on the Options page. Microsoft's example for that page restores an earlier backup of the same database over itself.
Confirm the fix
After the restore, sys.databases should show the database ONLINE. Microsoft documents that the FamilyGUID of a backup stays the same when the database is restored, so the restored database's family_guid should equal the value you noted from RESTORE HEADERONLY. Compare table row counts for two or three key tables against a source you trust. Run RESTORE VERIFYONLY on the backup before relying on it for a larger move; Microsoft lists it as supported with MOVE.
Example (illustrative): on sql02, a deployment script created an empty database named SalesDB at 09:00. At 11:30 an administrator restores SalesDB_full.bak, taken on sql01, into SalesDB and gets error 3154. RESTORE HEADERONLY shows DatabaseName = SalesDB, so the names match; the family GUIDs differ because the shell was created on sql02. The shell's files total 16 MB (8 MB data, 8 MB log), so dropping it costs nothing. RESTORE FILELISTONLY on the backup lists a 40 GB data file and an 8 GB log file, which total 48 GB, and the target volume has 120 GB free. Restoring needs 48 GB and leaves 72 GB (120 minus 48). The administrator drops the empty shell and restores without REPLACE.
What to watch afterwards
- Change deployment scripts so they do not create a database that a later restore will target by name.
- Keep a short runbook line: HEADERONLY first, FILELISTONLY second, restore third.
- After any restore that used REPLACE, record who ran it and which database it replaced.
- Keep one tail-log backup step in the runbook for full-recovery databases.
- Check that jobs referring to the database still point at the right one after a name change.
Read next
Related articles you may want next.
- Backup & RecoverySQL Server restore error 5133: directory lookup for the file failed (restoring to another server)RESTORE fails with error 5133 on a new server because the backup remembers the old file paths. Use FILELISTONLY and WITH MOVE to restore safely.Read article
- Backup & RecoverySQL Server restore error 3101: exclusive access could not be obtained because the database is in useRESTORE fails with error 3101 because sessions still use the database. Find them, clear them safely, restore, and avoid the data-loss traps.Read article
- Backup & RecoverySQL Server database stuck in 'Restoring...': finish the restore or recover it safelyWhy a SQL Server database sits in Restoring, how to tell a live restore from NORECOVERY or a standby copy, and how to recover without losing logs.Read article
Risks and limits
These commands have not been run or lab-tested. Microsoft's pages describe the safety check by name in one place and by family GUID in others; the documented behaviour has been quoted as written, and a particular version may apply one or both. The RESTORE pages are written for SQL Server on Windows, and file paths here use Windows form.
WITH REPLACE can destroy committed work and overwrite the wrong files. Do not add it just to make an error go away, and do not run it against production without a verified copy of the existing database. If the backup is of a database on a hosted server that also carries other databases, confirm the target name twice before you run a restore.
NetLeverage includes a daily full disaster-recovery backup of each hosted server at no extra charge. Talk to an engineer.
Sources
- RESTORE Statements - Arguments (Transact-SQL) — Microsoft Learn, page dated 2026-06-23, accessed 18 November 2026
- RESTORE Statements (Transact-SQL) — Microsoft Learn, page dated 2026-09-21, accessed 18 November 2026
- Restore a database backup using SSMS — Microsoft Learn, page dated 2025-02-27, accessed 18 November 2026
- RESTORE Statements - HEADERONLY (Transact-SQL) — Microsoft Learn, page dated 2026-07-21, accessed 18 November 2026
- RESTORE Statements - FILELISTONLY (Transact-SQL) — Microsoft Learn, page dated 2026-07-21, accessed 18 November 2026
- sys.database_recovery_status (Transact-SQL) — Microsoft Learn, page dated 2026-08-24, accessed 18 November 2026
- sys.database_files (Transact-SQL) — Microsoft Learn, page dated 2026-09-21, accessed 18 November 2026
- Database Engine events and errors (3000 to 3999) — Microsoft Learn, page dated 2026-10-27, accessed 18 November 2026
- DROP DATABASE (Transact-SQL) — Microsoft Learn, page dated 2026-10-09, accessed 18 November 2026
This article was originally published on .