Skip to content

Commit 0e71711

Browse files
committed
Add @KeepCdc parameter
Add the KEEP_CDC option to the RESTORE DATABASE ... WITH RECOVERY command.
1 parent 11ac1d4 commit 0e71711

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

‎sp_DatabaseRestore.sql‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ ALTER PROCEDURE [dbo].[sp_DatabaseRestore]
3131
@DatabaseOwner sysname = NULL,
3232
@SetTrustworthyON BIT = 0,
3333
@FixOrphanUsers BIT = 0,
34+
@KeepCdc BIT = 0,
3435
@Execute CHAR(1) = Y,
3536
@FileExtensionDiff NVARCHAR(128) = NULL,
3637
@Debug INT = 0,
@@ -1490,13 +1491,18 @@ END
14901491
-- Put database in a useable state
14911492
IF @RunRecovery = 1
14921493
BEGIN
1493-
SET @sql = N'RESTORE DATABASE ' + @RestoreDatabaseName + N' WITH RECOVERY' + NCHAR(13);
1494+
SET @sql = N'RESTORE DATABASE ' + @RestoreDatabaseName + N' WITH RECOVERY';
1495+
1496+
IF @KeepCdc = 1
1497+
SET @sql = @sql + N', KEEP_CDC';
14941498

1495-
IF @Debug = 1 OR @Execute = 'N'
1496-
BEGIN
1497-
IF @sql IS NULL PRINT '@sql is NULL for RESTORE DATABASE: @RestoreDatabaseName';
1498-
PRINT @sql;
1499-
END;
1499+
SET @sql = @sql + NCHAR(13);
1500+
1501+
IF @Debug = 1 OR @Execute = 'N'
1502+
BEGIN
1503+
IF @sql IS NULL PRINT '@sql is NULL for RESTORE DATABASE: @RestoreDatabaseName';
1504+
PRINT @sql;
1505+
END;
15001506

15011507
IF @Debug IN (0, 1) AND @Execute = 'Y'
15021508
EXECUTE @sql = [dbo].[CommandExecute] @DatabaseContext=N'master', @Command = @sql, @CommandType = 'RECOVER DATABASE', @Mode = 1, @DatabaseName = @UnquotedRestoreDatabaseName, @LogToTable = 'Y', @Execute = 'Y';

0 commit comments

Comments
 (0)