PDA

View Full Version : Alter table, mass insert new field in all tables


druidfog
05-13-2009, 03:47 PM
I have a script that's installed on over 1000 domains. The script creates 3 tables per domain and I have all of them stored in a single database. So, tables are organized like this:

domain1
domain1_1
domain1_2
domain2
domain2_1
domain2_2
etc

For some new functionality I need to add a new field in one of the tables for every domain.

In domainxx_1 tables I can successfully do this for every table in phpmyadmin to add the new field:
ALTER TABLE `domain_1` ADD `mainmessage` TEXT NOT NULL AFTER `autoapprove` ;

Is there a way to mass update all tables with a single statement vs doing each table manually? I've tried a wildcard such as ALTER TABLE `%_1` but I see that's not valid. Thx

abduraooft
05-13-2009, 04:50 PM
Use some server side script to make a look for creating the names of your tables dynamically.