MySQL去除表、字段注释
1、拼接去除表注释的语句,得到语句后执行
sql
# 根据实际情况,修改database_name
SELECT
CONCAT('ALTER TABLE ',table_name," COMMENT = '';")
FROM information_schema.TABLES
WHERE table_type='BASE TABLE'
AND TABLE_SCHEMA='database_name';
2、拼接去除字段的语句,得到语句后执行
sql
# 根据实际情况,修改database_name
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'
小尾巴~~
只要有积累,就会有进步