Home > Database > Mysql Tutorial > Are primary keys automatically indexed in MySQL?

Are primary keys automatically indexed in MySQL?

PHPz
Release: 2023-09-05 13:33:14
forward
1010 people have browsed it

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)
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template