Is the primary key automatically indexed in MySQL?

MySQLMySQLi Database

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.

raja
Published on 29-Nov-2018 12:52:02
Advertisements