在 MariaDB 中显示表
发布于
在MariaDB中,是一个管理语句,它列出了给定数据库中的非表,序列和视图。SHOW TABLES``TEMPORARY
语法
语法是这样的:
SHOW [FULL] TABLES [FROM db_name]
[LIKE 'pattern' | WHERE expr]
示例
下面是一个演示示例:
SHOW TABLES;
输出:
+------------------------+
| Tables_in_krankykranes |
+------------------------+
| Customers |
| Dogs |
| Gameshow |
| OrderItems |
| Orders |
| PetShow |
| Pets |
| Products |
| Vendors |
| t1 |
+------------------------+这向我们显示了当前数据库中的表,在本例中为数据库。KrankyKranes
显示表类型
我们可以使用修饰符返回表类型:FULL
USE sakila;
SHOW FULL TABLES;
输出:
+----------------------------+------------+
| Tables_in_sakila | Table_type |
+----------------------------+------------+
| actor | BASE TABLE |
| address | BASE TABLE |
| category | BASE TABLE |
| city | BASE TABLE |
| country | BASE TABLE |
| customer | BASE TABLE |
| customer_list | VIEW |
| film | BASE TABLE |
| film_actor | BASE TABLE |
| film_category | BASE TABLE |
| film_list | VIEW |
| film_text | BASE TABLE |
| inventory | BASE TABLE |
| language | BASE TABLE |
| nicer_but_slower_film_list | VIEW |
| payment | BASE TABLE |
| rental | BASE TABLE |
| sales_by_film_category | VIEW |
| sales_by_store | VIEW |
| staff | BASE TABLE |
| staff_list | VIEW |
| store | BASE TABLE |
+----------------------------+------------+在这里,我切换到数据库,然后运行.我们可以看到返回的一些表实际上是视图。Sakila``SHOW FULL TABLES
如前所述,该语句返回表、序列和视图。
条款LIKE
该子句(如果单独存在)指示要匹配的表名:LIKE
SHOW FULL TABLES
LIKE 'f%';
输出:
+-----------------------+------------+
| Tables_in_sakila (f%) | Table_type |
+-----------------------+------------+
| film | BASE TABLE |
| film_actor | BASE TABLE |
| film_category | BASE TABLE |
| film_list | VIEW |
| film_text | BASE TABLE |
+-----------------------+------------+条款WHERE
该子句可用于根据给定条件筛选结果:WHERE
SHOW FULL TABLES
WHERE Table_type = 'BASE TABLE';
输出:
+------------------+------------+
| Tables_in_sakila | Table_type |
+------------------+------------+
| actor | BASE TABLE |
| address | BASE TABLE |
| category | BASE TABLE |
| city | BASE TABLE |
| country | BASE TABLE |
| customer | BASE TABLE |
| film | BASE TABLE |
| film_actor | BASE TABLE |
| film_category | BASE TABLE |
| film_text | BASE TABLE |
| inventory | BASE TABLE |
| language | BASE TABLE |
| payment | BASE TABLE |
| rental | BASE TABLE |
| staff | BASE TABLE |
| store | BASE TABLE |
+------------------+------------+我们还可以通过约定对第一列使用子句,其中是数据库的名称:WHERE``Tables_in_dbname``dbname
SHOW FULL TABLES
WHERE Tables_in_sakila = 'customer';
输出:
+------------------+------------+
| Tables_in_sakila | Table_type |
+------------------+------------+
| customer | BASE TABLE |
+------------------+------------+