使用单个查询将 MySQL 中所有列名设为小写
我们首先创建一个 -
mysql> create table DemoTable1 -> ( -> StudentFirstName varchar(20), -> StudentLastName varchar(20), -> StudentAge int, -> StudentCountryName varchar(20) -> ); Query OK, 0 rows affected (4.20 sec)
现在让我们 MYSQL 中所有列名改为小写 -
mysql> select concat('alter table ', table_name, ' change `', column_name, '` `', -> lower(column_name), '` ', column_type, ';') -> from information_schema.columns where table_schema = 'demo';
这将产生以下输出 -
+-----------------------------------------------------------------------------------------------------------------+ | concat('alter table ', table_name, ' change `', column_name, '` `', lower(column_name), '` ', column_type, ';') | +-----------------------------------------------------------------------------------------------------------------+ | alter table demotable1 change `StudentFirstName` `studentfirstname` varchar(20); | | alter table demotable1 change `StudentLastName` `studentlastname` varchar(20); | | alter table demotable1 change `StudentAge` `studentage` int(11); | | alter table demotable1 change `StudentCountryName` `studentcountryname` varchar(20); | | alter table mytable change `MyEuroColumn` `myeurocolumn` varchar(5); | +-----------------------------------------------------------------------------------------------------------------+ 5 rows in set (0.00 sec)
广告