MySQL 用mysql显示表;我可以在忽略大小写的同时按表名排序吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6528531/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
With mysql show tables; can I sort by table name while ignoring case?
提问by Matthew
Is there a way to sort the list of tables returned by mysql's 'show tables' command?
有没有办法对 mysql 的“show tables”命令返回的表列表进行排序?
mysql> show tables;
I'd like to sort alphabetically by the table name.
我想按表名的字母顺序排序。
EDIT:
编辑:
As pointed out by one of the answers, they are already in alphabetical order. However, A != a. Is there a way to ignore case in the sort?
正如其中一个答案所指出的,它们已经按字母顺序排列。然而,A != a。有没有办法忽略排序中的大小写?
回答by Christopher Manning
Query information_schema and replace database_name
with the name of the database you want to return the tables from
查询 information_schema 并替换database_name
为要从中返回表的数据库的名称
SELECT table_name, engine
FROM information_schema.tables
WHERE table_type = 'BASE TABLE' AND table_schema='database_name'
ORDER BY table_name ASC;
回答by Bohemian
They are already in alphabetical order!
它们已经按字母顺序排列了!
回答by Vagif
SELECT CONCAT(`table_name`, '')
FROM information_schema.tables
order by 1 asc
All you need, just transform the table_name
to regular varchar type. And then order it as usual string.
您只需table_name
要将其转换为常规 varchar 类型即可。然后像往常一样订购它。
回答by Siraj Khan
Please try this one and replace database name accordingly.
请尝试这个并相应地替换数据库名称。
SELECT table_name FROM INFORMATION_SCHEMA.tables WHERE table_schema = 'database_name' ORDER BY table_name ASC;
SELECT table_name FROM INFORMATION_SCHEMA.tables WHERE table_schema = 'database_name' ORDER BY table_name ASC;