1. 程式人生 > >mysql批量修改列大小寫

mysql批量修改列大小寫

小記:

SELECT -- t2.table_schema,t2.table_name,t2.column_name,upper(t2.column_name),t2.column_type,
-- case when t2.is_nullable='NO' then 'not null' else 'null' end as isnull1,t2.column_comment,
CONCAT('ALTER table ',t2.table_schema,'.',t2.table_name,' CHANGE ',' \`',t2.column_name,'\` \`',UPPER(t2.column_name),'\` ',
t2.column_type,' ',CASE WHEN t2.is_nullable='NO' THEN 'not null' ELSE 'null' END,' COMMENT ''',t2.column_comment,''';') AS c
  FROM information_schema.tables t1, information_schema.columns t2
 WHERE t1.table_schema = 'db1'
   AND t1.table_type = 'base table'
   AND t1.table_schema = t2.table_schema
   AND t1.table_name = t2.table_name