Is the primary key automatically indexed in MySQL?

Yes, primary key is automatically indexed in MySQL because primary key, index, etc gets stored into B-trees. All engines including InnoDB as well as MyISAM automatically supports the primary key to be indexed.

The primary key is implicitly indexed in InnoDB, MyISAM, and other engines.

Let us create a table with primary key −

mysql> create table DemoIndex
   -> (
   -> Id int not null,
   -> primary key(Id)
   -> );
Query OK, 0 rows affected (1.21 sec)

In the above table, Id is implicitly indexed.

Updated on: 30-Jul-2019

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started