Skip to content

Instantly share code, notes, and snippets.

@brazilnut2000
Created March 31, 2017 21:11
Show Gist options
  • Save brazilnut2000/69793aa50f1651e8e4cdc2939a08115f to your computer and use it in GitHub Desktop.
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
-- 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