Yes, primary keys are automatically indexed in MySQL because primary keys, indexes, etc. are stored in B-trees. All engines including InnoDB and MyISAM automatically support primary key indexes.
Primary keys are implicitly indexed in InnoDB, MyISAM, and other engines.
Let’s create a table with a 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.
The above is the detailed content of Are primary keys automatically indexed in MySQL?. For more information, please follow other related articles on the PHP Chinese website!