Last active
November 12, 2019 19:41
-
-
Save greggnakamura/166d3a27bedaae446226496ee3ef2989 to your computer and use it in GitHub Desktop.
SQL Server: Restore DB with alter and restore in a since query
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
USE [master] | |
alter database [databaseName] | |
set single_user with rollback immediate | |
GO | |
RESTORE DATABASE [databaseName] FROM DISK = 'path\to\db\backup.bak' | |
WITH REPLACE | |
GO | |
alter database [databaseName] | |
set multi_user with rollback immediate | |
GO | |
--http://screencast.com/t/CBubnbnOb6X | |
-- example | |
USE [master] | |
alter database exeterHospital | |
set single_user with rollback immediate | |
GO | |
RESTORE DATABASE exeterHospital FROM DISK = 'C:\_DB_Backups\exeterHospital.bak' | |
WITH REPLACE | |
GO | |
alter database exeterHospital | |
set multi_user with rollback immediate | |
GO |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment