MySQL按表名排序显示表?

MySQL按表名排序显示表?

从INFORMATION_SCHEMA.TABLES中的table_name属性进行排序,并利用ASC或DESC将其升序或降序排序。语法如下 −

SELECT table_name
FROM information_schema.tables
WHERE table_type = 'BASE TABLE' AND table_schema='yourDatabaseName'
ORDER BY table_name DESC;

使用名称为sample的数据库,并拥有一些表。首先,我们将显示所有表,然后我们将在表名上进行排序。显示所有表的查询如下 −

mysql> show tables;

以下是输出−

+--------------------------+
| Tables_in_sample         |
+--------------------------+
| blobsizedemo             |
| insert_prevent           |
| insertrecord_selecttable |
| insertrecordprevent      |
| mytable                  |
| newlinedemo              |
| notequaloperator         |
| sumofeverydistinct       |
| yourtable                |
+--------------------------+
9 rows in set (0.00 sec)

这是按表名排序的查询。现在,让我们按ORDER BY子句降序显示所有表−

mysql> SELECT table_name
   -> FROM information_schema.tables
   -> WHERE table_type = 'BASE TABLE' AND table_schema='sample'
   -> ORDER BY table_name DESC;

以下是输出−

+--------------------------+
| TABLE_NAME               |
+--------------------------+
| yourtable                |
| sumofeverydistinct       |
| notequaloperator         |
| newlinedemo              |
| mytable                  |
| insertrecordprevent      |
| insertrecord_selecttable |
| insert_prevent           |
| blobsizedemo             |
+--------------------------+
9 rows in set (0.00 sec)

阅读更多:MySQL 教程

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程