postgresql Postgres 没有主键的缺点
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12679940/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Postgres No Primary Key Drawback
提问by AlexGad
Is there any drawback to not having a primary key for a table in Postgres? Since all data is stored unordered in the heap anyway, is the primary key just a way to enforce a unique key and an index at the same time? Or is there a fundamental feature that a primary key provides in a table as opposed to a table that does not have a primary key?
在 Postgres 中没有表的主键有什么缺点吗?由于无论如何所有数据都无序存储在堆中,主键是否只是一种同时强制唯一键和索引的方法?或者,与没有主键的表相比,主键是否在表中提供了基本功能?
采纳答案by jcern
Per the Postgres documentation (http://www.postgresql.org/docs/9.2/static/sql-createtable.html):
根据 Postgres 文档 ( http://www.postgresql.org/docs/9.2/static/sql-createtable.html):
Technically, PRIMARY KEY is merely a combination of UNIQUE and NOT NULL, but identifying a set of columns as primary key also provides metadata about the design of the schema, as a primary key implies that other tables can rely on this set of columns as a unique identifier for rows.
从技术上讲,PRIMARY KEY 只是 UNIQUE 和 NOT NULL 的组合,但是将一组列标识为主键还提供了有关架构设计的元数据,因为主键意味着其他表可以依赖这组列作为行的唯一标识符。
From my experience, I have created plenty of tables without them. But some replication solutions require there be a primary key, or at the single column identifier per row.
根据我的经验,我创建了很多没有它们的表。但是一些复制解决方案需要有一个主键,或者每行的单个列标识符。