Home  >  Article  >  Database  >  Are primary keys automatically indexed in MySQL?

Are primary keys automatically indexed in MySQL?

PHPz
PHPzforward
2023-09-05 13:33:14971browse

MySQL 中主键是否自动建立索引?

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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete