Restore Database by Store Procedure

  • Hey guys!

    I need to create a procedure with Restore Database command in many applications in differente platforms.

    But i can't "use master".

    How do I do it?

  • rodrigoosrn (7/26/2014)


    Hey guys!

    I need to create a procedure with Restore Database command in many applications in differente platforms.

    But i can't "use master".

    How do I do it?

    You can use "dynamic" sql, here is a simple example

    😎

    USE tempdb;

    GO

    CREATE PROCEDURE dbo.GET_MASTER_DB_NAME

    AS

    DECLARE @SQL_STR NVARCHAR(MAX) = N'

    USE master;

    SELECT DB_NAME() AS THIS_DB_NAME;

    '

    EXEC (@SQL_STR);

    GO

    EXEC dbo.GET_MASTER_DB_NAME

    DROP PROCEDURE dbo.GET_MASTER_DB_NAME;

    Result

    THIS_DB_NAME

    -------------

    master

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply