Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Restore Database by Store Procedure Expand / Collapse
Author
Message
Posted Saturday, July 26, 2014 12:58 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Saturday, December 6, 2014 5:01 AM
Points: 3, Visits: 10
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?
Post #1596527
Posted Sunday, July 27, 2014 3:00 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 1:49 AM
Points: 2,533, Visits: 7,100
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
Post #1596587
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse