Sign in with Microsoft
Sign in or create an account.
Select a different account.
You have multiple accounts
Choose the account you want to sign in with.


When you restore a database from a backup by using the WITH REPLACE option in Microsoft SQL Server 2012, the physical file names of the restored database that comes from the backup database may overwrite the physical file names of the existing database.

For example, consider the following scenario:

  • You have two instances of SQL Server, InstanceA and InstanceB.

  • You have a database that has the same name, SQLDB, on each instance of SQL Server.

  • On InstanceA, the SQLDB database data file name is DB1_InstanceA.mdf and the log file name is DB1_InstanceA.ldf.

  • On InstanceB, the SQLDB database data file name is DB1_InstanceB.mdf and the log file name is DB1_InstanceB.ldf.

  • You try to restore a backup of the SQLDB database from InstanceA over the SQLDB database from InstanceB by using the WITH REPLACE option of the RESTORE command.

In this scenario, the physical file names on SQLDB on InstanceB are changed to DB1_InstanceA.mdf and DB1_InstanceA.ldf. 


This behavior is by design in SQL Server 2012.


To work around this issue, do not use the WITH REPLACE option of the RESTORE command. Instead, use the WITH MOVE option.

Note The WITH MOVE option provides an option to change the physical file name.

More Information

The WITH MOVE option is necessary only the first time that you use the RESTORE command. When you try to restore a database from the backup, SQL Server compares the recovery fork values of the database. Then, the backup set takes the following actions, depending on whether those values match:

  • If there is a match, the backup set continues to use the file names of the target database.

  • If the values are different, the backup set replaces the physical file names of the target database by using the names from the backup set.

When you use the WITH MOVE option together with the RESTORE command, the following actions are taken:

  1. A new recovery fork is created on the target server.

  2. On the next restore operation, the recovery fork IDs from the backup set are matched with the IDs of the target server.

  3. A RESTORE command that is used together with the WITH REPLACE option keeps the physical names on the target server.

For more information about the RESTORE command, see RESTORE (Transact-SQL)

Need more help?

Want more options?

Explore subscription benefits, browse training courses, learn how to secure your device, and more.

Communities help you ask and answer questions, give feedback, and hear from experts with rich knowledge.

Was this information helpful?

What affected your experience?
By pressing submit, your feedback will be used to improve Microsoft products and services. Your IT admin will be able to collect this data. Privacy Statement.

Thank you for your feedback!