本文提供了一种批量删除MySQL生产环境中数据库表的注释或表字段注释的方法,通过脚本实现高效维护表结构的清晰性。
一、表注释修改
1.获取删除MySQL数据库表注释脚本
select
concat('ALTER TABLE ',table_name," COMMENT = '';")
fROM information_schema.TABLES
where table_type='BASE TABLE' and TABLE_SCHEMA='database_name';
2.将获取的sql执行即可
二、表字段注释修改
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 = 'database_name'
2.将获取的sql执行即可