且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Mysql:修剪数据库中的所有字段

更新时间:2023-02-08 16:30:23

晚了几年,但可能会帮助其他人: 此代码修剪表"your_table"的所有字段. 可以扩展为以相同的方式在整个数据库上工作....

Some years late, but might help others: This code trims all fields of a the table "your_table". Could be expanded to work on the whole database in the same way....

SET SESSION group_concat_max_len = 1000000;
select concat('update your_table set ',group_concat(concat('`',COLUMN_NAME, '` = trim(`',COLUMN_NAME,'`)')),';')
   FROM INFORMATION_SCHEMA.COLUMNS
    WHERE table_name = 'your_table'
    into @trimcmd;

prepare s1 from @trimcmd;
execute s1;
DEALLOCATE PREPARE s1;