当前位置: 移动技术网 > IT编程>数据库>MSSQL > 代码实现批量生成sql语句

代码实现批量生成sql语句

2019年01月05日  | 移动技术网IT编程  | 我要评论

张暖雅全婐照片原图,九道婴仙,noopenqq

代码实现批量生成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' 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网