mysql按字母顺序获取表列名称 [英] mysql get table column names in alphabetical order
本文介绍了mysql按字母顺序获取表列名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以查询MySQL数据库以按字母顺序获取表的列名?我知道
Is it possible to query a MySQL database to get the column names of a table in alphabetical order? I know that
SHOW COLUMNS `table_name`;
或
DESCRIBE `table_name`;
会给我一个表中的列的列表(以及其他信息),但是可以更改查询以便按字母顺序对列进行排序.添加ORDER BY'Field'不起作用,它给出了语法错误.
will give me a list of the columns in a table (along with other info), but is it possible to alter the query in order to get the columns sorted alphabetically. Adding ORDER BY 'Field' didn't work, it gave a syntax error.
推荐答案
ANSI INFORMATION_SCHEMA表(在本例中为INFORMATION_SCHEMA.COLUMNS)在MySQL中提供了更大的灵活性:
The ANSI INFORMATION_SCHEMA tables (in this case, INFORMATION_SCHEMA.COLUMNS) provide more flexibility in MySQL:
SELECT c.column_name
FROM INFORMATION_SCHEMA.COLUMNS c
WHERE c.table_name = 'tbl_name'
-- AND c.table_schema = 'db_name'
ORDER BY c.column_name
这篇关于mysql按字母顺序获取表列名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文