让我们首先创建一个表 -
mysql> create table DemoTable ( UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY, UserFirstName varchar(20), UserLastName varchar(20), UserAge int, UserCountryName varchar(20) );
现在检查表的描述。
mysql> desc DemoTable;
这将产生以下输出 -
+-----------------+-------------+------+-----+---------+----------------+ | 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)
以下是在使用 SELECT 时将大小写转换为小写列名的查询。
mysql> SELECT LOWER(COLUMN_NAME) FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = 'DemoTable';
这将产生以下输出 -
+--------------------+ | LOWER(COLUMN_NAME) | +--------------------+ | userage | | usercountryname | | userfirstname | | userid | | userlastname | +--------------------+ 5 rows in set (0.03 sec)