当前位置:网站首页>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
边栏推荐
猜你喜欢

What are the advantages of a differential probe over a conventional probe

WasmEdge 0.10.0 发布!全新的插件扩展机制、Socket API 增强、LLVM 14 支持

利尔达低代码数据大屏,铲平数据应用开发门槛

containerd1.5.5的安装

Implementation of code scanning login

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

Wasmedge 0.10.0 release! New plug-in extension mechanism, socket API enhancement, llvm 14 support

Fire fighting work and measures in Higher Vocational Colleges

罗氏线圈工作原理

与普通探头相比,差分探头有哪些优点
随机推荐
Integer partition
Comment supprimer le crosstalk SiC MOSFET?
Preparation for Oracle 11g RAC deployment on centos7
FatMouse and Cheese
找合适的PMP机构只需2步搞定,一查二问
887. egg drop
利尔达低代码数据大屏,铲平数据应用开发门槛
Quelle est la largeur de bande du serveur de bavardage sonore pour des centaines de millions de personnes en même temps?
FatMouse and Cheese
抖音服务器带宽有多大,才能供上亿人同时刷?
Protection range and optimization of motor protector for hoist equipment
Avframe Memory Management API
【Go ~ 0到1 】 第三天 6月27 slice,map 与 函数
叠加阶梯图和线图及合并线图和针状图
小程序 :遍历list里面的某个数组的值,等同于 for=“list” list.comment里面的某一项
Discussion on the improvement and application of the prepayment system in the management of electricity charge and price
[go ~ 0 to 1] on the first day, June 24, variables, conditional judgment cycle statement
Application of current limiting protector in preventing electrical fire in shopping malls
Basic twelve style classes for duilib
罗氏线圈工作原理