表的主键代表您在最重要查询中使用的列或列集合。它有一个关联的索引,以提高查询性能。查询性能受益于 NOT NULL 优化,因为它不能包含任何 NULL 值。在 InnoDB 存储引擎中,表数据在物理上是根据主键列组织的,以便进行超快速的查找和排序。The primary key for a table represents the column or set of
columns that you use in your most vital queries. It has an
associated index, for fast query performance. Query performance
benefits from the NOT NULL optimization,
because it cannot include any NULL values.
With the InnoDB storage engine, the table
data is physically organized to do ultra-fast lookups and sorts
based on the primary key column or columns.
如果你的表很大且重要,但没有明显的列或列集可用作主键,你可以创建一个带有自增值的单独列作为主键。这些唯一的 ID 可以在使用外键连接表时,作为指向其他表中对应行的指针。If your table is big and important, but does not have an obvious column or set of columns to use as a primary key, you might create a separate column with auto-increment values to use as the primary key. These unique IDs can serve as pointers to corresponding rows in other tables when you join tables using foreign keys.