Category Archives: Failed to Restore Backup Database

Restore Backup Database Failed Because Database Is in Use

How to restore backup database while the existing database is in use

Sometimes, backing up and restoring database is not so straight forward. I used to get the issue of the current database is in use and cannot restore the backup database. But my life is saved when I found the following scripts. 🙂

USE MASTER
GO

ALTER DATABASE MyDatabase
SET SINGLE_USER WITH ROLLBACK IMMEDIATE
Go

RESTORE DATABASE MyDatabase
FROM DISK = N'[file address]'
Go

ALTER DATABASE MyDatabase
SET MULTI_USER with ROLLBACK IMMEDIATE
Go

 

Advertisements

Leave a comment

Filed under Failed to Restore Backup Database, Microsoft SQL Server