Last active
July 11, 2018 06:26
-
-
Save huyttq/6679466 to your computer and use it in GitHub Desktop.
Restore MS SQL Server DB with replace
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
use [master] | |
Declare @BackupFileLocation varchar(max) | |
Declare @BackupMDFFileName varchar(max) | |
Declare @BackupLogFileName varchar(max) | |
Declare @ImportTesterMDFFileName varchar(max) | |
Declare @ImportTesterLogFileName varchar(max) | |
set @BackupFileLocation = | |
N'\\file-path\bk.bak' | |
set @BackupLogicalMDFFileName = N'LogicalFileName' | |
set @BackupLogicalLogFileName = N'LogicalFileName_log' | |
set @ImportTesterMDFFileName = N'C:\file-path\Test.mdf' | |
set @ImportTesterLogFileName = N'C:\file-path\Test_log.ldf' | |
--Begin Try | |
use [Master] | |
RESTORE DATABASE [Test] | |
FROM DISK = @BackupFileLocation WITH FILE = 1, | |
MOVE @BackupLogicalMDFFileName TO @ImportTesterMDFFileName, | |
MOVE @BackupLogicalLogFileName TO @ImportTesterLogFileName, | |
NOUNLOAD, REPLACE, STATS = 10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment