I have a section on this in my article on dynamic SQL that you can use as a starting point: https://www.sommarskog.se/dynamic_sql.html#alldatabases.
alter table script on all my databases
There´s almost 300 databases in the server, almost all of them have the same structure (same tables and columns), well, I need to add 2 more columns to the clients table on every single one of them... I´ve been through several posts about different sintaxys and i'm not getting it at all...
¿Is there any example or tutorial where can I get some help?
I'll apreciate any help of you all
Also, there's 3 types of databases in here: the A, B and Cs... and I just need to alter the A & B types...
Sign in to comment
Sort by: Most helpful
Hi @ExEEEEEEE ,
Try to use
sp_msforeachdb, it allows us to execute a T-sql statement against every database in the current SQL Server instance
But it is strongly recommended to avoid using undocumented features of SQL Server in your Production environment.
Add columns in multiple databases
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.