MySQL为多个表增加相同字段(列)

打算为多个表增加相同字段,这些表的名字在一个表里存着,一个一个修改太麻烦,查到下面这种拼接SQL语句的方式:

select group_concat('alter table ', table_schema, '.', table_name, ' add column LINDEX INT(10);' SEPARATOR "") from information_schema.tables where table_schema='你的数据库名' and table_name like 'test%';

按照个人需求修改,

select group_concat('alter table ', table_schema, '.', table_name, ' add column side_direction varchar(20);' SEPARATOR "") from information_schema.tables where table_schema='你的数据库名' and table_name in (SELECT table_name FROM 存放待增加字段的表名的表);

猜你喜欢

转载自blog.csdn.net/whuzhang16/article/details/109600028