• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Mysql 数据库批量调整字段名称中的特殊字符

互联网 diligentman 7天前 12次浏览

根据以下语句获取处理语句;

SELECT    case when DATA_TYPE= 'varchar' then CONCAT('ALTER TABLE ',TABLE_NAME , ' CHANGE ' ,COLUMN_NAME,'  ', REPLACE(COLUMN_NAME, '_', '') ,' ',DATA_TYPE,'(',CHARACTER_MAXIMUM_LENGTH,')' ,' ; ') elseCONCAT('ALTER TABLE ',TABLE_NAME , ' CHANGE ' ,COLUMN_NAME,'  ', REPLACE(COLUMN_NAME, '_', '') ,' ',DATA_TYPE,' ; ') end        as '语句',
TABLE_SCHEMA AS '库名',
TABLE_NAME AS '表名',
COLUMN_NAME '列名',
ORDINAL_POSITION AS '列的排列顺序',
COLUMN_DEFAULT AS '默认值',
IS_NULLABLE AS '是否为空',
DATA_TYPE AS '数据类型',
CHARACTER_MAXIMUM_LENGTH AS '字符最大长度',
NUMERIC_PRECISION AS '数值精度(最大位数)',
NUMERIC_SCALE AS '小数精度',
COLUMN_TYPE AS 列类型,
COLUMN_KEY 'KEY',
EXTRA AS '额外说明',
COLUMN_COMMENT AS '注释' FROM
information_schema.`COLUMNS` WHERE
TABLE_SCHEMA = '数据库名称'
    and COLUMN_NAME <> REPLACE(COLUMN_NAME, '_', '');
    

根据查询的语句,执行后,即可调整数据库所有字段特殊字符;


喜欢 (0)