Skip to content

Instantly share code, notes, and snippets.

@Mpdreamz
Last active October 6, 2015 03:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mpdreamz/2930551 to your computer and use it in GitHub Desktop.
Save Mpdreamz/2930551 to your computer and use it in GitHub Desktop.
Force sql restore from file
----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