Restore database SQL Server command with replace

Restore database SQL Server command with replace option is used when we need overwrite an existing database from a backup. The T-SQL command for same is shown below.

RESTORE DATABASE [AdventureWorks2014] FROM DISK = N'E:\Ahmad\AdventureWorks2014.bak' 
WITH REPLACE

The above overwrites the AdventureWorks2014 from the backup device.

When restoring from GUI, check the REPLACE option in Options pane

restore database sql server command with replace

   

The Replace command overwrites the existing database from the database in the backup device even if the database name in backup device differs from the database name being restored. As the replace command overwrites the database, it may result in loss of committed work if log is not being backed up in full recovery or bulk load recovery model.

REPLACE command should be used cautiously because of the above mentioned reasons.

 
Like us on FaceBook Join the fastest growing SQL Server group on FaceBook

   

Leave a Reply

Your email address will not be published.