Created
March 31, 2017 21:11
-
-
Save brazilnut2000/69793aa50f1651e8e4cdc2939a08115f to your computer and use it in GitHub Desktop.
Create a copy of a database by restoring and renaming from a 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
-- SOURCE: http://stackoverflow.com/questions/6267273/how-to-restore-to-a-different-database-in-sql-server | |
-- Get the files, note the logical names of the .mdf and .ldf files | |
restore filelistonly from disk='E:\MSSQL\Backup\NewProjectExplorer\NewProjectExplorer_20170330.bak' | |
-- Restore and rename the backup | |
restore database [NewName] from disk = 'E:\MSSQL\Backup\NewProjectExplorer\NewProjectExplorer_20170330.bak' | |
with | |
move '[LogicalNameForMdf]' to 'E:\MSSQL\[NewName].mdf', | |
move '[LogicalNameForLdf]' to 'E:\MSSQL\[NewName]_log.ldf' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment