代码实现批量生成sql语句

代码实现批量生成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' 
(0)
上一篇 2022年3月21日
下一篇 2022年3月21日

相关推荐