Wednesday, August 4, 2010

Database Restore Script

This is a quick database restore script.  It sets the database to SINGLE_USER so you don't get any "database in use" errors, then restores the database, then sets it back to MULTI_USER.

You need to run all the commands together.  It didn't work for me when I tried to run them separately.



   1:  ALTER DATABASE MyAppDB SET SINGLE_USER WITH ROLLBACK IMMEDIATE
   2:    RESTORE DATABASE MyAppDB FROM DISK = 'E:\DBBackups\MyApp_db_201008032143.BAK' WITH REPLACE
   3:    ALTER DATABASE MyAppDB SET MULTI_USER