当前位置:网站首页>批量修改表和表中字段排序规则
批量修改表和表中字段排序规则
2022-06-28 08:36:00 【CHENFU_JAVA】
批量修改表中字段排序规则
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 = 'chenfu' #要修改的数据库名称
and DATA_TYPE = 'text'
and COLLATION_NAME='utf8mb4_0900_ai_ci';
- 执行结果如下
ALTER TABLE `order` MODIFY `title` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci COMMENT '标题';
ALTER TABLE `order_detail` MODIFY `title` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '标题';
批量修改表排序规则
SELECT
CONCAT("ALTER TABLE `",TABLE_NAME,
"` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;") AS target_tables
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA="chenfu" AND TABLE_TYPE="BASE TABLE";
- 执行结果如下
ALTER TABLE `order` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
ALTER TABLE `order_detail` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
参考
边栏推荐
猜你喜欢

How to suppress SiC MOSFET crosstalk?
![[cloud native | kubernetes] in depth understanding of pod (VI)](/img/ae/f16f5c090251ab603b88ddadff7eb3.png)
[cloud native | kubernetes] in depth understanding of pod (VI)

TCP那点事

叠加阶梯图和线图及合并线图和针状图

用Pytorch搭建第一个神经网络且进行优化

Error: `brew cask` is no longer a `brew` command. Use `brew <command> --cask` instead.

VMware Workstation related issues

第六届智能家居亚洲峰会暨精品展(Smart Home Asia 2022)将于10月在沪召开
![[.Net6] GRP server and client development cases, as well as the access efficiency duel between the minimum API service, GRP service and traditional webapi service](/img/19/296f124becb87461accf8b73b0a8bc.png)
[.Net6] GRP server and client development cases, as well as the access efficiency duel between the minimum API service, GRP service and traditional webapi service

电子元器件销售ERP管理系统哪个比较好?
随机推荐
duilib 入门基础十二 样式类
About RAC modifying scan IP
DB
Basic twelve style classes for duilib
How do people over 40 allocate annuity insurance? Which product is more suitable?
NPM clean cache
About using font icons in placeholder
Introduction, compilation, installation and deployment of Doris learning notes
Wasmedge 0.10.0 release! New plug-in extension mechanism, socket API enhancement, llvm 14 support
Selenium reptile
Trailing Zeroes (II)
【云原生 | Kubernetes篇】深入了解Pod(六)
Error: `brew cask` is no longer a `brew` command. Use `brew <command> --cask` instead.
The 6th smart home Asia 2022 will be held in Shanghai in October
Case tool
[introduction to SQL for 10 days] day4 Combined Query & specified selection
Redis deployment under Linux & redis startup
Kali installation configuration
Installing MySQL under Linux
B_ QuRT_ User_ Guide(28)