Skip to content

Commit

Permalink
Merge pull request BrentOzarULTD#3442 from gdoddsy/issue_3429
Browse files Browse the repository at this point in the history
Update sp_DatabaseRestore.sql
  • Loading branch information
BrentOzar authored Feb 18, 2024
2 parents 4a09e00 + 8fca53a commit aa84eb9
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion sp_DatabaseRestore.sql
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ ALTER PROCEDURE [dbo].[sp_DatabaseRestore]
@Version VARCHAR(30) = NULL OUTPUT,
@VersionDate DATETIME = NULL OUTPUT,
@VersionCheckMode BIT = 0,
@FileNamePrefix NVARCHAR(260) = NULL
@FileNamePrefix NVARCHAR(260) = NULL,
@RunStoredProcAfterRestore NVARCHAR(260) = NULL
AS
SET NOCOUNT ON;
SET STATISTICS XML OFF;
Expand Down Expand Up @@ -1637,6 +1638,29 @@ END;'
-- If test restore then blow the database away (be careful)
IF @TestRestore = 1
BEGIN

IF @RunStoredProcAfterRestore IS NOT NULL AND LEN(LTRIM(@RunStoredProcAfterRestore)) > 0
BEGIN
PRINT 'Attempting to run ' + @RunStoredProcAfterRestore
SET @sql = N'EXEC ' + @RestoreDatabaseName + '.' + @RunStoredProcAfterRestore

IF @Debug = 1 OR @Execute = 'N'
BEGIN
IF @sql IS NULL PRINT '@sql is NULL when building for @RunStoredProcAfterRestore'
PRINT @sql
END

IF @RunRecovery = 0
BEGIN
PRINT 'Unable to run Run Stored Procedure After Restore as database is not recovered. Run command again with @RunRecovery = 1'
END
ELSE
BEGIN
IF @Debug IN (0, 1) AND @Execute = 'Y'
EXEC sp_executesql @sql
END
END

SET @sql = N'DROP DATABASE ' + @RestoreDatabaseName + NCHAR(13);

IF @Debug = 1 OR @Execute = 'N'
Expand Down

0 comments on commit aa84eb9

Please sign in to comment.