alter table script on all my databases

ExEEEEEEE 1 Reputation point

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...

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,673 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Erland Sommarskog 100.9K Reputation points MVP

    I have a section on this in my article on dynamic SQL that you can use as a starting point:

    0 comments No comments

  2. YufeiShao-msft 7,056 Reputation points

    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.

    0 comments No comments