Skip to content

Commit aa84eb9

Browse files
authored
Merge pull request #3442 from gdoddsy/issue_3429
Update sp_DatabaseRestore.sql
2 parents 4a09e00 + 8fca53a commit aa84eb9

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

sp_DatabaseRestore.sql

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ ALTER PROCEDURE [dbo].[sp_DatabaseRestore]
3939
@Version VARCHAR(30) = NULL OUTPUT,
4040
@VersionDate DATETIME = NULL OUTPUT,
4141
@VersionCheckMode BIT = 0,
42-
@FileNamePrefix NVARCHAR(260) = NULL
42+
@FileNamePrefix NVARCHAR(260) = NULL,
43+
@RunStoredProcAfterRestore NVARCHAR(260) = NULL
4344
AS
4445
SET NOCOUNT ON;
4546
SET STATISTICS XML OFF;
@@ -1637,6 +1638,29 @@ END;'
16371638
-- If test restore then blow the database away (be careful)
16381639
IF @TestRestore = 1
16391640
BEGIN
1641+
1642+
IF @RunStoredProcAfterRestore IS NOT NULL AND LEN(LTRIM(@RunStoredProcAfterRestore)) > 0
1643+
BEGIN
1644+
PRINT 'Attempting to run ' + @RunStoredProcAfterRestore
1645+
SET @sql = N'EXEC ' + @RestoreDatabaseName + '.' + @RunStoredProcAfterRestore
1646+
1647+
IF @Debug = 1 OR @Execute = 'N'
1648+
BEGIN
1649+
IF @sql IS NULL PRINT '@sql is NULL when building for @RunStoredProcAfterRestore'
1650+
PRINT @sql
1651+
END
1652+
1653+
IF @RunRecovery = 0
1654+
BEGIN
1655+
PRINT 'Unable to run Run Stored Procedure After Restore as database is not recovered. Run command again with @RunRecovery = 1'
1656+
END
1657+
ELSE
1658+
BEGIN
1659+
IF @Debug IN (0, 1) AND @Execute = 'Y'
1660+
EXEC sp_executesql @sql
1661+
END
1662+
END
1663+
16401664
SET @sql = N'DROP DATABASE ' + @RestoreDatabaseName + NCHAR(13);
16411665

16421666
IF @Debug = 1 OR @Execute = 'N'

0 commit comments

Comments
 (0)