Need to create a procedure under a db

  • Hello,

    I need to dynamically switch the db context to another db and need to create a procedure inside that db. Can you kindly help me with the sample script?

    Thanks.

  • Do you need to create the procedure in all DB's?  Only some of the DBs?  Do you need to change anything in the procedure definition dynamically also to match.

     

    Please elaborate on the requirements and maybe a more honed solution to your problem can be found.

     

    However at first glance you would be looking at "sp_msforeachdb" or writing yourself a cursor of sorts to loop through and create the procedure for you.

  • Where do you want to run the code from? SSMS? SQLCMD? C# app? Something else?

    The absence of evidence is not evidence of absence.
    Martin Rees

    You can lead a horse to water, but a pencil must be lead.
    Stan Laurel

  • And what kind of stored procedure?  Is it for DBAs/Maintenance, etc or is it "production" code or ???

     

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • This was removed by the editor as SPAM

  • This was removed by the editor as SPAM

  • This was removed by the editor as SPAM

  • This was removed by the editor as SPAM

  • Muct1977 wrote:

    You can consult:

    Screenshot (116)

    And just exactly how does that solve the problem "dynamically" as what the OP asked for?

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • And I just realized that this is an old post the OP has not responded.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • This was removed by the editor as SPAM

  • This was removed by the editor as SPAM

  • This was removed by the editor as SPAM

Viewing 13 posts - 1 through 12 (of 12 total)

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