mirror of
https://github.com/jbranchaud/til
synced 2026-01-07 00:58:02 +00:00
Add Show Indexes For A Table as a mysql til
This commit is contained in:
@@ -10,7 +10,7 @@ smart people at [Hashrocket](http://hashrocket.com/).
|
|||||||
For a steady stream of TILs from a variety of rocketeers, checkout
|
For a steady stream of TILs from a variety of rocketeers, checkout
|
||||||
[til.hashrocket.com](https://til.hashrocket.com/).
|
[til.hashrocket.com](https://til.hashrocket.com/).
|
||||||
|
|
||||||
_535 TILs and counting..._
|
_536 TILs and counting..._
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -232,6 +232,7 @@ _535 TILs and counting..._
|
|||||||
### MySQL
|
### MySQL
|
||||||
|
|
||||||
- [List Databases And Tables](mysql/list-databases-and-tables.md)
|
- [List Databases And Tables](mysql/list-databases-and-tables.md)
|
||||||
|
- [Show Indexes For A Table](mysql/show-indexes-for-a-table.md)
|
||||||
|
|
||||||
### Phoenix
|
### Phoenix
|
||||||
|
|
||||||
|
|||||||
33
mysql/show-indexes-for-a-table.md
Normal file
33
mysql/show-indexes-for-a-table.md
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
# Show Indexes For A Table
|
||||||
|
|
||||||
|
When describing a table, such as the table `users`:
|
||||||
|
|
||||||
|
```sql
|
||||||
|
> describe users;
|
||||||
|
+------------+-----------------------+------+-----+---------+----------------+
|
||||||
|
| Field | Type | Null | Key | Default | Extra |
|
||||||
|
+------------+-----------------------+------+-----+---------+----------------+
|
||||||
|
| id | mediumint(8) unsigned | NO | PRI | NULL | auto_increment |
|
||||||
|
| first_name | varchar(80) | NO | | NULL | |
|
||||||
|
| last_name | varchar(80) | NO | | NULL | |
|
||||||
|
| email | varchar(80) | NO | UNI | NULL | |
|
||||||
|
+------------+-----------------------+------+-----+---------+----------------+
|
||||||
|
```
|
||||||
|
|
||||||
|
I can see in the `Key` column that there is a primary key and a unique key
|
||||||
|
for this table on `id` and `email`, respectively.
|
||||||
|
|
||||||
|
These keys are indexes. To get more details about each of the indexes on
|
||||||
|
this table, we can use the
|
||||||
|
[`show indexes`](https://dev.mysql.com/doc/refman/5.7/en/show-index.html)
|
||||||
|
command.
|
||||||
|
|
||||||
|
```sql
|
||||||
|
> show indexes in users;
|
||||||
|
+-------+------------+--------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
|
||||||
|
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
|
||||||
|
+-------+------------+--------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
|
||||||
|
| users | 0 | PRIMARY | 1 | id | A | 0 | NULL | NULL | | BTREE | | |
|
||||||
|
| users | 0 | unique_email | 1 | email | A | 0 | NULL | NULL | | BTREE | | |
|
||||||
|
+-------+------------+--------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
|
||||||
|
```
|
||||||
Reference in New Issue
Block a user