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, July 26, 2014 1:25 PM
Points: 1, Visits: 1
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
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Today @ 1:51 PM
Points: 1,902, Visits: 5,234
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