首页 > 数据库技术 > 详细

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

时间:2020-02-29 23:05:34      阅读:90      评论:0      收藏:0      [点我收藏+]

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

SELECT 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 );

 

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

原文:https://www.cnblogs.com/rhyheart/p/12386412.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!