代码实现批量生成sql语句
程序员文章站
2022-04-27 20:52:36
代码实现批量生成sql语句
select
concat(
'alter table ',
table_schema, '...
代码实现批量生成sql语句
select concat( 'alter table ', table_schema, '.', table_name, ' modify column ', column_name, ' ', column_type, ' ', #if(is_nullable = 'yes', ' ', 'not null '), if(column_default is null, '', if( data_type in ('char', 'varchar') or data_type in ('date', 'datetime', 'timestamp') and column_default != 'current_timestamp', concat(' default ''', column_default,''''), concat(' default ', column_default) ) ), if(extra is null or extra='','',concat(' ',extra)), ' comment ''', column_comment, ''';' )col from information_schema.columns where table_schema = 'whiski'; #and table_name = 'ws_adminuser'