当前位置:Gxlcms > 数据库问题 > 批量更新数据库表以及表字段编码

批量更新数据库表以及表字段编码

时间:2021-07-01 10:21:17 帮助过:4人阅读

CONCAT(ALTER TABLE , table_name, CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin;) FROM information_schema.TABLES WHERE TABLE_SCHEMA = db_name and TABLE_COLLATION != utf8_bin

查询需要更新编码的表字段,并生成相应的更新SQL

SELECT CONCAT(ALTER TABLE `, table_name, ` MODIFY `, column_name, ` , DATA_TYPE, (, CHARACTER_MAXIMUM_LENGTH, ) 
CHARACTER SET UTF8 COLLATE utf8_bin
, (CASE WHEN IS_NULLABLE = NO THEN NOT NULL ELSE ‘‘ END), ;) FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = db_name AND DATA_TYPE = varchar AND ( CHARACTER_SET_NAME != utf8 OR COLLATION_NAME != utf8_general_ci );

 

批量更新数据库表以及表字段编码

标签:arc   concat   lte   nbsp   select   arch   case   alter   info   

人气教程排行