Created
July 31, 2014 02:28
-
-
Save sgaulding/9d5067fe2d084350e188 to your computer and use it in GitHub Desktop.
Command Prompt MS-SQL Restore from Backup
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
rem ******************************************* Use Master | |
SqlCmd -E -S localhost -Q "USE MASTER" | |
rem ******************************************* Restoring <Database Name> database | |
SqlCmd -E -S localhost -Q "ALTER DATABASE [<Database Name>] SET SINGLE_USER WITH ROLLBACK AFTER 5 SECONDS" | |
del " <Database Backup Full File Name>.bak" | |
SqlCmd -E -S localhost -Q "BACKUP DATABASE [<Database Name>] TO DISK = ‘<Database Backup Full File Name>’" | |
SqlCmd -E -S localhost -Q "drop database [<Database Name>] " | |
copy “<New Database Backup Full File Name>.bak” "<Database Backup Directory>" | |
SqlCmd -E -S localhost -Q "restore database [<Database Name>] from disk = ‘<Database Backup Full File Name>’ with move ‘<Database Name>’ to ‘<Database Full File Name>.mdf', move '<Database Name>_log' to ‘<Database Log Full File Name>.ldf'" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment