频道栏目
首页 > 资讯 > SQL Server > 正文

代码实现批量生成sql语句

18-06-14        来源:[db:作者]  
收藏   我要投稿

代码实现批量生成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' 
相关TAG标签
上一篇:云计算sed命令集锦
下一篇:网络编程基本知识与实践 - 一对多特性实现方法
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站