我们创建好了数据表,那么我们该怎么去查看数据表列表呢?
一、查看数据表列表的语法结构
SHOW TABLES [FROM db_name] [LIKE ‘pattern’ | WHERE expr]
FROM db_name表示,我们不仅可以查看当前数据库里的数据表,还可以查看别的数据库里的数据表
mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| tb1 |
+----------------+
1 row in set (0.00 sec)
mysql>
mysql> show tables from mysql;
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| columns_priv |
| db |
| func |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| host |
| proc |
| procs_priv |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
17 rows in set (0.01 sec)
mysql>
验证用户打开的是哪个数据库
可见,还是在我们test这个数据库下,可以既能查看到test本身的数据表,还能查看到别的数据库里的数据表。
二、查看数据表结构的语法
SHOW COLUMNS FROM tbl_name
mysql> show columns from tb1;
+----------+---------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+---------------------+------+-----+---------+-------+
| username | varchar(20) | YES | | NULL | |
| age | tinyint(3) unsigned | YES | | NULL | |
| salaty | float(8,2) unsigned | YES | | NULL | |
+----------+---------------------+------+-----+---------+-------+
3 rows in set (0.01 sec)