Lower case column names with MySQL SELECT?


Let us first create a table −

mysql> create table DemoTable
   (
   UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY,
   UserFirstName varchar(20),
   UserLastName varchar(20),
   UserAge int,
   UserCountryName varchar(20)
   );
Query OK, 0 rows affected (0.27 sec)

Now check the description of table.

mysql> desc DemoTable;

This will produce the following output −

+-----------------+-------------+------+-----+---------+----------------+
| Field           | Type        | Null | Key | Default | Extra          |
+-----------------+-------------+------+-----+---------+----------------+
| UserId          | int(11)     | NO   | PRI | NULL    | auto_increment |
| UserFirstName   | varchar(20) | YES  |     | NULL    |                |
| UserLastName    | varchar(20) | YES  |     | NULL    |                |
| UserAge         | int(11)     | YES  |     | NULL    |                |
| UserCountryName | varchar(20) | YES  |     | NULL    |                |
+-----------------+-------------+------+-----+---------+----------------+
5 rows in set (0.00 sec)

Following is the query to convert case to lower case column names while using SELECT.

mysql> SELECT LOWER(COLUMN_NAME) FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = 'DemoTable';

This will produce the following output −

+--------------------+
| LOWER(COLUMN_NAME) |
+--------------------+
| userage            |
| usercountryname    |
| userfirstname      |
| userid             |
| userlastname       |
+--------------------+
5 rows in set (0.03 sec)

Updated on: 30-Jul-2019

594 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements