Created
July 24, 2012 16:37
-
-
Save josuebasurto/3171082 to your computer and use it in GitHub Desktop.
Restore a database first making the database single user then rollingback other users transactions, then restoring the backup.
This file contains 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
/* | |
JB 20120724 - MS SQL SERVER 2008 R2 | |
Restore a database first making the database single user then rollingback other users transactions, then restoring the backup. | |
Notes: | |
- This script is stored and shared as is. | |
- Might Work on other versions. | |
- Need owner privileges over database. | |
*/ | |
--Get out of wherever you're working on! And let's go masteR! | |
use master | |
go | |
--Single user a database | |
ALTER DATABASE [ <<Database Name>> ] --Replace varaible for database name | |
SET SINGLE_USER WITH ROLLBACK IMMEDIATE | |
GO | |
--Restore Database | |
RESTORE DATABASE [ <<Database Name>> ] --Replace varaible for database name | |
FROM DISK = N'<<Bak Filepath>>' --Replace fot database filepath | |
WITH FILE = 1, NOUNLOAD, REPLACE, STATS = 10 | |
GO |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment