开发者

Dynamically ALTERing MySQL tables to add missing fields on INSERT

开发者 https://www.devze.com 2023-03-11 10:36 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消