Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@sgaulding
Created July 31, 2014 02:28
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 sgaulding/9d5067fe2d084350e188 to your computer and use it in GitHub Desktop.
Save sgaulding/9d5067fe2d084350e188 to your computer and use it in GitHub Desktop.
Command Prompt MS-SQL Restore from Backup
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