December 15, 2022 at 5:02 am
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.
December 15, 2022 at 8:55 am
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.
December 15, 2022 at 8:57 am
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
December 15, 2022 at 9:18 pm
And what kind of stored procedure? Is it for DBAs/Maintenance, etc or is it "production" code or ???
--Jeff Moden
Change is inevitable... Change for the better is not.
December 28, 2022 at 9:53 am
This was removed by the editor as SPAM
December 28, 2022 at 9:55 am
This was removed by the editor as SPAM
December 29, 2022 at 6:33 am
This was removed by the editor as SPAM
April 11, 2023 at 4:26 am
This was removed by the editor as SPAM
April 11, 2023 at 3:24 pm
You can consult:
And just exactly how does that solve the problem "dynamically" as what the OP asked for?
--Jeff Moden
Change is inevitable... Change for the better is not.
April 11, 2023 at 3:26 pm
And I just realized that this is an old post the OP has not responded.
--Jeff Moden
Change is inevitable... Change for the better is not.
April 20, 2023 at 4:25 am
This was removed by the editor as SPAM
June 28, 2023 at 8:33 am
This was removed by the editor as SPAM
January 8, 2024 at 7:58 am
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