Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
issam
Starting Member
30 Posts |
Posted - 2008-02-27 : 04:56:03
|
| 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]GOCREATE PROCEDURE TEST1 ASBEGIN DECLARE @something varchar(12) set @something = '123'ENDeverything 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 writeEXEC(' CREATE DATABASE [tomasdb]USE [tomasdb]CREATE PROCEDURE TEST1 ASBEGIN 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 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-02-27 : 05:02:54
|
| I dont think you can change context of db by executing USE statement from within a db using EXEC |
 |
|
|
issam
Starting Member
30 Posts |
Posted - 2008-02-27 : 05:11:15
|
| what about copying a stored procedure from one database to another ? |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-02-27 : 05:34:07
|
| You can copy it using transfer objects task in SSIS |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-02-27 : 05:38:27
|
quote: Originally posted by issam what about copying a stored procedure from one database to another ?
Scipt out at source db and run it in target dbMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|