Skip to content

Instantly share code, notes, and snippets.

@PartTimeLegend
Created October 14, 2016 11:08
Show Gist options
  • Select an option

  • Save PartTimeLegend/ed72f7c172c8a481248288b72db536f8 to your computer and use it in GitHub Desktop.

Select an option

Save PartTimeLegend/ed72f7c172c8a481248288b72db536f8 to your computer and use it in GitHub Desktop.
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