码迷,mamicode.com
首页 > 其他好文 > 详细

动态将表中的列名全部转换成小写

时间:2015-10-22 14:00:22      阅读:168      评论:0      收藏:0      [点我收藏+]

标签:

/*
  动态将表的列名改为小写
*/
select concat_ws(‘‘,‘alter table ‘,a.TABLE_NAME,‘ modify ‘,lower(a.COLUMN_NAME),‘ ‘,a.Column_type, case when a.is_nullable = ‘NO‘ THEN ‘ not null ‘ else null end,
       case when a.Column_default is null then null
            when a.Column_default = ‘‘ then ‘ default ‘‘‘‘‘
            when a.Column_default is not null and a.data_type in (‘bigint‘,‘int‘,‘decimal‘) then  concat_ws(‘‘,‘ default ‘,a.Column_default)
            when a.Column_default is not null and a.data_type in (‘varchar‘,‘char‘) then  concat_ws(‘‘,‘ default ‘,‘‘‘‘,a.Column_default,‘‘‘‘)
            when a.Column_default is not null and a.data_type in (‘timestamp‘,‘datetime‘) then  concat_ws(‘‘,‘ default ‘,a.Column_default) 
       else null end     
       ,‘ comment ‘‘‘,a.Column_comment,‘‘‘‘,‘;‘) aa
  from information_schema.`COLUMNS` a 
 where a.TABLE_SCHEMA =‘ibgs‘
   and a.TABLE_NAME =‘sys_config‘;

 

动态将表中的列名全部转换成小写

标签:

原文地址:http://www.cnblogs.com/Yongzhouunknown/p/4900616.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!