Last active
October 6, 2015 03:47
-
-
Save Mpdreamz/2930551 to your computer and use it in GitHub Desktop.
Force sql restore from file
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
----Force database into single user Mode | |
ALTER DATABASE db_name | |
SET SINGLE_USER WITH | |
ROLLBACK IMMEDIATE | |
----Restore Database | |
RESTORE DATABASE db_name | |
FROM DISK = 'D:\db_name.bak' | |
WITH REPLACE, | |
MOVE 'db_name' TO 'D:\SQLServer\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\db_name.mdf', | |
MOVE 'db_name_log' TO 'D:\SQLServer\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\db_name_log.ldf' | |
/*If there is no error in statement before database will be in multiuser | |
mode. | |
If an error occurs please execute the following command it will convert | |
database back into multi user.*/ | |
ALTER DATABASE db_name SET MULTI_USER | |
GO |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment