数据库中快速更改同库下多张表中具有相同字段的数据类型:
分四步走:
一、利用系统表,快速找到含有指定字段的表清单
select table_name from information_schema.column where table_schema = '指定数据库' and column_name = '指定字段名'
二、清单列出后确定修改后的字段名,然后可以直接利用步骤一中的信息进行加工处理(修改字段时如果表内数据较多,则修改起来会特别慢,如果想要快一些,可以选择清空表,根据实际情况自行判断,因为有一些数据是没有源头的,所以不推荐这么做)
快速生成清表语句
select concat('truncate table ',table_name,';') from information_schema.column where table_schema = '指定数据库' and column_name = '指定字段名'
三、快速生成更改表字段语句
select concat('alter table ',table_name,' modify column 字段名 字段类型;') from information_schema.column where table_schema = '指定数据库' and column_name = '指定字段名'
四、复制出语句,然后执行即可;
推荐一个好用的公众号 “数据与编程之美”