为什么要使用主键? [英] Why use primary keys?
问题描述
除了标识表中的唯一列之外,还使用哪些主键?不能仅通过在列上使用自动增量约束来完成此操作?我知道PK和FK用于关联不同的表,但是不能仅使用join来做到这一点吗?
What are primary keys used aside from identifying a unique column in a table? Couldn't this be done by simply using an autoincrement constraint on a column? I understand that PK and FK are used to relate different tables, but can't this be done by just using join?
使用主键加入数据库时,数据库在做什么以提高性能?
Basically what is the database doing to improve performance when joining using primary keys?
推荐答案
主要是为了使用外键实现引用完整性,当拥有PK时,它还会在后台创建索引,这样您在查找值时就无需进行表扫描
Mostly for referential integrity with foreign keys,, When you have a PK it will also create an index behind the scenes and this way you don't need table scans when looking up values
这篇关于为什么要使用主键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!