Create DB within a stored proc - doubt

  • hi,

    I have a stored proc 'MySP' running in context of master db - it contains the foll. stmt:

    --- create proc

    if exists (select name from sysobjects where name = 'mySP')

        drop proc mySP

    GO

    CREATE PROC mySP

    if exists (select name from sysdatabases where name = 'MyDB')

                 begin

                       drop database MyDB

                       create database MyDB

                 end

    else

          create database MyDB

    --set permission to MyDB

    --calling another stored proc

     

    Now when this is  executed - if there is a db named MyDB - it shd be dropped and created else freshly create the db and then all following stmts mst executed in context of master after the create statment's execution

    how do i get this back to master context after the create stmt

    plz help.

    thank you,

    nsh

  • Natalie/Nisha - pl. do not cross post - follow this thread here!







    **ASCII stupid question, get a stupid ANSI !!!**

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

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