有多张表,需要加同一个字段,虽然mysql没提供可直接批量新增字段的功能,但可以曲线救国呀,用CONCAT拼接函数,显示出新增字段的语句,执行即可:
SELECT CONCAT('alter table ',table_schema,'.',table_name,' ADD COLUMN `base_url` varchar(500) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL AFTER `remark`;')
from information_schema.tables
where table_schema='op_xxx_manager'
and table_name like 'batch_xxx_detail_%';
执行:
大功告成!