设为首页 加入收藏

TOP

代码实现批量生成sql语句
2018-06-15 08:48:00 】 浏览:158
Tags:代码 实现 批量 生成 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' 
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇sql的datetime数据类型实例解析 下一篇JAVA学习之表关系、多表查询等实..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目