美文网首页
MySQL 批量清除注释

MySQL 批量清除注释

作者: zhanglb12 | 来源:发表于2024-12-06 14:42 被阅读0次

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

相关文章

网友评论

      本文标题:MySQL 批量清除注释

      本文链接:https://www.haomeiwen.com/subject/jkebsjtx.html