简体   繁体   English

Oracle IDENTITY 列与 PRIMARY KEY

[英]Oracle IDENTITY column versus PRIMARY KEY

Having trouble finding anything definite about whether it's needed to specify that an IDENTITY column as PRIMARY KEY in Oracle 12.2c.无法确定是否需要在 Oracle 12.2c 中将IDENTITY列指定为PRIMARY KEY Does an IDENTITY column automatically create an index, like a PK ? IDENTITY列是否会自动创建索引,例如PK Is it just being redudant?只是重复吗? I do believe you can have an IDENTITY column and separate PK, though we are not doing that.我相信你可以有一个IDENTITY列和单独的 PK,尽管我们没有这样做。

ID NUMBER AS IDENTITY PRIMARY KEY == ID NUMBER AS IDENTITY ?

An IDENTITY column can be and often is useful as primary key, but it doesn't have to be. IDENTITY列可以并且通常用作主键,但并非必须如此。

The identity column is very useful for the surrogate primary key column.标识列对于代理主键列非常有用。 When you insert a new row into the identity column, Oracle auto-generates and insert a sequential value into the column.当您将新行插入标识列时,Oracle 会自动生成并将顺序值插入该列。

https://www.oracletutorial.com/oracle-basics/oracle-identity-column/ https://www.oracletutorial.com/oracle-basics/oracle-identity-column/

Does an IDENTITY column automatically create an index, like a PK? IDENTITY 列是否会自动创建索引,例如 PK?

No. An identity column is just a column auto-populated with a sequentially generated number.不,标识列只是用顺序生成的数字自动填充的列。 You can use it however you want, but the typical use is as a synthetic primary key.您可以随心所欲地使用它,但典型的用途是作为合成主键。

Is it just being redundant?它只是多余的吗?

No.不。

I do believe you can have an IDENTITY column and separate PK我相信你可以有一个 IDENTITY 列和单独的 PK

Yes, you can.是的你可以。

though we are not doing that.虽然我们没有这样做。

Fine, if you mean you are not having a separate PK column in addition to the identity column.好的,如果您的意思是除了身份列之外没有单独的 PK Defining a PK constraint over the identity column would be a good idea.在标识列上定义 PK约束将是一个好主意。

It's a common mistake to mix logical and physical organization of data.混合数据的逻辑和物理组织是一个常见的错误。

You successfully mixed 3 orthogonal concepts:您成功混合了 3 个正交概念:

  • logical: PRIMARY KEY constraint逻辑: PRIMARY KEY约束
  • physical: INDEX物理: INDEX
  • automatic value generation: IDENTITY column自动值生成: IDENTITY

Does an IDENTITY column automatically create an index, like a PK? IDENTITY 列是否会自动创建索引,例如 PK? Is it just being redudant?只是重复吗?

Those questions are very version dependent.这些问题非常依赖于版本。 IDENTITY itself was introduced in Oracle 12.x. IDENTITY本身是在 Oracle 12.x 中引入的。

I do believe you can have an IDENTITY column and separate PK, though we are not doing that.我相信你可以有一个 IDENTITY 列和单独的 PK,尽管我们没有这样做。

You are correct here.你在这里是对的。

Auto value generation, logical constraint and physical data organization are orthogonal to each other.自动值生成、逻辑约束和物理数据组织是相互正交的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM