Dynamically ALTERing MySQL tables to add missing fields on INSERT
I'm attempting to merge data from one MySQL database into another. The problem is, some of the tables in Source_DB
have fields that the matching table in Target_DB
does not have.
Is开发者_StackOverflow社区 there a way to automatically ALTER
the table in Target_DB
to add these missing fields as they are found?
Or should I go about it another way, like doing a first pass where I compare each table to first add any missing fields?
You could query the INFORMATION_SCHEMA.COLUMNS
on each DB and figure out what's missing with a NOT IN query and then using the data in the INFORMATION_SCHEMA.COLUMNS
dynamically generate the DDL.
Or you could use a tool like MySQL Compare to do it.
精彩评论