
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
Difference between SHOW INDEX, SHOW INDEXES and SHOW KEYS in MySQL?
There is no difference between show index, show indexes and show keys. They have similar meaning.
Let us first create a table −
mysql> create table DemoTable1549 -> ( -> EmployeeId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> EmployeeName varchar(20) -> ); Query OK, 0 rows affected (0.82 sec)
Following is the query to create an index −
mysql> create index name_index1 on DemoTable1549(EmployeeName); Query OK, 0 rows affected (0.41 sec) Records: 0 Duplicates: 0 Warnings: 0
Following is the query for SHOW INDEX −
mysql> show index from DemoTable1549;
This will produce the following output −
+---------------+------------+-------------+--------------+--------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+ | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | Visible | +---------------+------------+-------------+--------------+--------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+ | demotable1549 | 0 | PRIMARY | 1 | EmployeeId | A | 0 | NULL | NULL | | BTREE | | | YES | | demotable1549 | 1 | name_index1 | 1 | EmployeeName | A | 0 | NULL | NULL | YES | BTREE | | | YES | +---------------+------------+-------------+--------------+--------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+ 2 rows in set (0.17 sec)
Here is the query for SHOW INDEXES −
mysql> show indexes from DemoTable1549;
This will produce the following output −
+---------------+------------+-------------+--------------+--------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+ | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | Visible | +---------------+------------+-------------+--------------+--------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+ | demotable1549 | 0 | PRIMARY | 1 | EmployeeId | A | 0 | NULL | NULL | | BTREE | | | YES | | demotable1549 | 1 | name_index1 | 1 | EmployeeName | A | 0 | NULL | NULL | YES | BTREE | | | YES | +---------------+------------+-------------+--------------+--------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+ 2 rows in set (0.00 sec)
Here is the query to implement SHOW KEYS −
mysql> show keys from DemoTable1549;
This will produce the following output −
+---------------+------------+-------------+--------------+--------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+ | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | Visible | +---------------+------------+-------------+--------------+--------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+ | demotable1549 | 0 | PRIMARY | 1 | EmployeeId | A | 0 | NULL | NULL | | BTREE | | | YES | | demotable1549 | 1 | name_index1 | 1 | EmployeeName | A | 0 | NULL | NULL | YES | BTREE | | | YES | +---------------+------------+-------------+--------------+--------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+ 2 rows in set (0.00 sec)
- Related Articles
- Show/view indexes in a MySQL Database
- MongoDB difference between show dbs and show databases?
- Only show tables with certain patterns in MySQL “show tables”?
- How to show that each MySQL enumeration has an index value?
- Group result in MySQL and show on list?
- Show constraints on table command in MySQL?
- How to customize `show processlist` in MySQL?
- Show column value twice in MySQL Select?
- Combine SELECT & SHOW command results in MySQL?
- Show MySQL host via SQL Command?
- Return order of MySQL SHOW COLUMNS?
- Python - Show which entries in a Pandas Index are NA
- Why SHOW DBS does not show my databases in MongoDB?
- Diagrammatically show the difference between the three types of muscle fibers.
- Remove specific fields/ rows and show other records in MySQL?

Advertisements