Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Creating a stored procedure in another database
Message
From
27/02/2008 04:50:44
Issam Mansour
Jordan Business Machines
Amman, Jordan
 
 
To
All
General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
Title:
Creating a stored procedure in another database
Environment versions
SQL Server:
SQL Server 2005
Miscellaneous
Thread ID:
01296757
Message ID:
01296757
Views:
41
From within a stored procedure in an existing database I'm creating a new database from the scratch.

In the query window if I write the statement:
CREATE DATABASE [tomasdb]

USE [tomasdb]
GO
CREATE PROCEDURE TEST1
AS
BEGIN
DECLARE @something varchar(12)
set @something = '123'
END

everything works ok and the database is created and the stored procedure Test1 is created within it.
However, if I want to do the same from another stored procedure (in another database), i.e. I write

EXEC('
CREATE DATABASE [tomasdb]
USE [tomasdb]
CREATE PROCEDURE TEST1
AS
BEGIN
DECLARE @something varchar(12)
set @something = ''123''
END
')

the problem I get is that I'm not allowed to put USE to change the execution context into [tomasdb] before the CREATE PROCEDURE statement.
My question is: how can I change the context in this situation / or / can I create the stored procedure in the [tomasdb] database somehow from outside (another context).

Thanks,
Tomas
Next
Reply
Map
View

Click here to load this message in the networking platform