Created
October 14, 2016 11:08
-
-
Save PartTimeLegend/ed72f7c172c8a481248288b72db536f8 to your computer and use it in GitHub Desktop.
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
| DECLARE @backupPath nvarchar(400);DECLARE @sourceDb nvarchar(50);DECLARE @sourceDb_log nvarchar(50);DECLARE @destDb nvarchar(50);DECLARE @destMdf nvarchar(100);DECLARE @destLdf nvarchar(100);DECLARE @sqlServerDbFolder nvarchar(100); SET @sourceDb = 'db1'SET @sourceDb_log = @sourceDb + '_log'SET @backupPath = 'E:\tmp\' + sourceDb + '.bak' --ATTENTION: file must already exist and SQL Server must have access to it SET @sqlServerDbFolder = 'E:\DB SQL\MSSQL11.MSSQLSERVER\MSSQL\DATA\' SET @destDb = 'db2' SET @destMdf = @sqlServerDbFolder + @destDb + '.mdf' SET @destLdf = @sqlServerDbFolder + @destDb + '_log' + '.ldf' BACKUP DATABASE @sourceDb TO DISK = @backupPath RESTORE DATABASE @destDb FROM DISK = @backupPath WITH REPLACE, MOVE @sourceDb TO @destMdf, MOVE @sourceDb_log TO @destLdf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment