当前位置:网站首页>Batch modify tables and sorting rules for fields in tables
Batch modify tables and sorting rules for fields in tables
2022-06-28 08:49:00 【CHENFU_ JAVA】
Batch modify the sorting rules of fields in the table
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' # Database name to modify
and DATA_TYPE = 'text'
and COLLATION_NAME='utf8mb4_0900_ai_ci';
- The results are as follows
ALTER TABLE `order` MODIFY `title` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci COMMENT ' title ';
ALTER TABLE `order_detail` MODIFY `title` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT ' title ';
Batch modify table collation
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";
- The results are as follows
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;
Reference resources
MySQL: Batch modify the sorting rules of table fields
MySQL Batch modify table character set collation
边栏推荐
- Wasmedge 0.10.0 release! New plug-in extension mechanism, socket API enhancement, llvm 14 support
- Trailing Zeroes (II)
- 如何抑制SiC MOSFET Crosstalk(串擾)?
- Common faults and solutions of Substation
- Build an integrated kubernetes in Fedora
- FatMouse and Cheese
- 为什么函数模板没有偏特化?
- Explain observer mode
- Protection range and optimization of motor protector for hoist equipment
- ffmpeg推流报错Failed to update header with correct duration.
猜你喜欢

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

Discussion on safety management of centralized maintenance construction site of substation under the mode of operation and maintenance

It only takes two steps to find the right PMP organization, one check and two questions

Error: `brew cask` is no longer a `brew` command. Use `brew <command> --cask` instead.
![[untitled]](/img/bb/213f213c695795daecb81a4cf2adcd.jpg)
[untitled]

Explain observer mode

Love analysis released the 2022 love analysis · it operation and maintenance manufacturer panorama report, and an Chao cloud was strongly selected!

如何抑制SiC MOSFET Crosstalk(串擾)?

The 6th smart home Asia 2022 will be held in Shanghai in October

罗氏线圈工作原理
随机推荐
罗氏线圈可以测量的大电流和频率范围
Force buckle 1884 Egg drop - two eggs
三体攻击(三维拆分加二分)
Mysql8.0 forgot the root password
叠加阶梯图和线图及合并线图和针状图
Build an integrated kubernetes in Fedora
STL -- binder
[introduction to SQL for 10 days] day4 Combined Query & specified selection
Solution: selenium common. exceptions. WebDriverException: Message: ‘chromedriver‘ execu
Why are function templates not partial specialization?
[reprint] STM32 GPIO type
MySQL8.0 忘记 root 密码
PMP从报考到拿证基本操作,了解PMP必看篇
Superimposed ladder diagram and line diagram and merged line diagram and needle diagram
Protection range and optimization of motor protector for hoist equipment
887. egg drop
Not so Mobile
Trailing Zeroes (II)
How to solve the problem of high concurrency and seckill
Which is a better ERP management system for electronic component sales?