让我们首先创建一个-
mysql> create table DemoTable1 -> ( -> StudentFirstName varchar(20), -> StudentLastName varchar(20), -> StudentAge int, -> StudentCountryName varchar(20) -> );
现在让我们在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)