飞哥的海

导航

MySQL:批量修改表的排序规则

SELECT
CONCAT('ALTER TABLE `', table_name, '` MODIFY `', column_name, '` ', DATA_TYPE,
'(', CHARACTER_MAXIMUM_LENGTH, ') CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci',
(CASE WHEN IS_NULLABLE = 'NO' THEN ' NOT NULL' ELSE '' END),
(case when IFNULL(column_comment,'')='' then '' else concat(' COMMENT \'' , column_comment ,'\'') end),
';') as `sql`
FROM information_schema.COLUMNS
WHERE 1=1
and TABLE_SCHEMA = 'zhnm' #要修改的数据库名称
and DATA_TYPE = 'varchar'
and COLLATION_NAME='utf8mb4_0900_ai_ci'

posted on   飞哥的海  阅读(431)  评论(0编辑  收藏  举报

努力加载评论中...
点击右上角即可分享
微信分享提示