fragments

May 27, 2018

MySQL查询某张表的列名

Last updated at: May 27, 2018

查询列名,返回多列:

SELECT COLUMN_NAME 
FROM `information_schema`.`COLUMNS` 
WHERE `TABLE_SCHEMA` = 'schema_name' AND TABLE_NAME = 'table_name';

查询列名,返回单列:

SELECT GROUP_CONCAT(COLUMN_NAME SEPARATOR ',') 
FROM `information_schema`.`COLUMNS` 
WHERE `TABLE_SCHEMA` = 'schema_name' AND TABLE_NAME = 'table_name';

参考

(30 words)