MySQL 批量清除注释

mysql清除注释,分两步!
逻辑:通过sql语句能查询数据库中的全部备注信息,然后将备注信息拼接成一个修改sql。

1.清除字段注解

SELECT
    concat(
        'alter table ',
        table_schema,
        '.',
        table_name,
        ' modify column `',
        column_name,
        '` ',
        column_type,
        ' ',

    IF (
        is_nullable = 'YES',
    
    IF (
        data_type IN ('timestamp'),
        ' null ',
        ' '
    ),
    'not null '
    ),

IF (
    column_default IS NULL,
    '',

IF (
    data_type IN ('char', 'varchar')
    OR data_type IN ('date', 'datetime')
    AND column_default != 'CURRENT_TIMESTAMP',
    concat(
    ' default ''',
        column_default,
        ''''
    ),
    concat(
        ' default ',

    IF (
        column_default = '',
        '''''',
        column_default
    )
    )

)
),

IF (
    extra IS NULL
    OR extra = '',
    '',
    concat(' ', extra)
),
 ' comment ''',
 ''';'
    ) s
FROM
    information_schema. COLUMNS
WHERE
    table_schema = '数据库名称'
    AND table_name = '表名';

2.清除表注解

SELECT
    concat(
        'alter table ',
        table_schema,
        '.',
        table_name,
        ' comment ''',
        ''';'
    ) s
FROM
    information_schema. COLUMNS
WHERE
    table_schema = '数据库名称'
GROUP BY
    TABLE_NAME;

生成的sql语句 导出到txt文件中 放到mysql执行就大功告成啦!

参考:https://blog.csdn.net/baidu_38752858/article/details/128445356

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容