SHOW INDEXES [FROM|IN]
SHOW INDEXES [FROM|IN]
语句用于列出指定表上的索引。SHOW INDEX [FROM | IN]
和 SHOW KEYS [FROM | IN]
是该语句的别名。包含该语句提供了 MySQL 兼容性。
语法图
ShowStmt:
ShowTargetFilterable:
ShowIndexKwd:
FromOrIn:
TableName:
示例
mysql> CREATE TABLE t1 (id int not null primary key auto_increment, col1 INT, INDEX(col1));
Query OK, 0 rows affected (0.12 sec)
mysql> SHOW INDEXES FROM t1;
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| t1 | 0 | PRIMARY | 1 | id | A | 0 | NULL | NULL | | BTREE | | |
| t1 | 1 | col1 | 1 | col1 | A | 0 | NULL | NULL | YES | BTREE | | |
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
rows in set (0.00 sec)
mysql> SHOW INDEX FROM t1;
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| t1 | 0 | PRIMARY | 1 | id | A | 0 | NULL | NULL | | BTREE | | |
| t1 | 1 | col1 | 1 | col1 | A | 0 | NULL | NULL | YES | BTREE | | |
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
rows in set (0.00 sec)
mysql> SHOW KEYS FROM t1;
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| t1 | 0 | PRIMARY | 1 | id | A | 0 | NULL | NULL | | BTREE | | |
| t1 | 1 | col1 | 1 | col1 | A | 0 | NULL | NULL | YES | BTREE | | |
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
rows in set (0.00 sec)
MySQL 兼容性
SHOW INDEXES [FROM|IN]
语句与 MySQL 完全兼容。如有任何兼容性差异,请在 GitHub 上提交 issue。
另请参阅
- SHOW CREATE TABLE
- DROP INDEX
- CREATE INDEX
看完两件小事
如果你觉得这篇文章对你挺有启发,我想请你帮我两个小忙:
- 把这篇文章分享给你的朋友 / 交流群,让更多的人看到,一起进步,一起成长!
- 关注公众号 「方志朋」,公众号后台回复「资源」 免费领取我精心整理的前端进阶资源教程