primary key(主键)是数据库术语,指在数据库表中唯一标识每一条记录的字段或字段组合。主键的值不能重复,也不能为空。在更广义的用法中,也可指"最主要的关键因素"。
/ˈpraɪ.mɛr.i kiː/
Every table in the database must have a primary key to uniquely identify each row.
数据库中的每张表都必须有一个主键,用来唯一标识每一行记录。
When designing the schema, we decided to use a composite primary key consisting of both the user ID and the timestamp, ensuring that no two entries from the same user at the same time could exist.
在设计数据库结构时,我们决定使用由用户ID和时间戳组成的复合主键,以确保同一用户在同一时间不会有重复的记录。
primary 源自拉丁语 primarius,意为"第一位的、首要的",由 primus(第一)派生而来。key 源自古英语 cǣġ,原指开锁的钥匙,后引申为"关键、要素"。primary key 作为数据库术语,最早随关系型数据库理论在20世纪70年代由 E.F. Codd 提出,用来指代在关系表中唯一标识记录的核心字段,如同一把"钥匙"能唯一打开对应的那条数据。