gpt4 book ai didi

postgresql - PostgreSQL 是否为没有指定主键的表创建一个内部键(可能是 int 类型)作为主键?

转载 作者:行者123 更新时间:2023-11-29 14:31:26 26 4
gpt4 key购买 nike

来自 https://stackoverflow.com/a/40597571/3284469

If you don't specify a primary key, RDBMS will help you choose an unique and non-null key, OR create an internal key (probably an int type) as primary key for this table.

你能给出一些“或”情况的例子吗,在这种情况下,RDBMS(特别是 PostgreSQL,也可能是 MySQL 或 SQL Server)为一个表创建一个“内部键(可能是 int 类型)作为主键”而没有指定的主键?

PostgreSQL 有类似 MySQL 的东西吗? ?

谢谢。

最佳答案

  • 对于 Postgres:

    来自 "5.4. System Columns" :

    oid

    The object identifier (object ID) of a row. This column is only present if the table was created using WITH OIDS, or if the default_with_oids configuration variable was set at the time. This column is of type oid (same name as the column); see Section 8.18 for more information about the type.

    ctid

    The physical location of the row version within its table. Note that although the ctid can be used to locate the row version very quickly, a row's ctid will change if it is updated or moved by VACUUM FULL. Therefore `ctid is useless as a long-term row identifier. The OID, or even better a user-defined serial number, should be used to identify logical rows.

    两者都接近您要搜索的内容,但有限制,您可以在文档中阅读。因此,正如手册所述,使用用户定义的 PK 是更好的选择。

  • 对于 SQL Server:

    存在未记录的伪列 %%physloc%%。它描述了一行的物理位置。但是,如果该行出于任何原因被物理移动,则可能会发生变化。而且它没有记录,也就是说,它的行为可能会在发布之间的任何时间发生变化,甚至只是补丁,或者它可能会被完全删除,恕不另行通知。因此,在这里使用用户定义的 PK 也是更好的选择。

关于postgresql - PostgreSQL 是否为没有指定主键的表创建一个内部键(可能是 int 类型)作为主键?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51235204/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com