Search code examples
sqloracle-databaseddl

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. Does an IDENTITY column automatically create an index, like a PK? Is it just being redudant? I do believe you can have an IDENTITY column and separate PK, though we are not doing that.

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

Solution

  • Does an IDENTITY column automatically create an index, like a 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

    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. Defining a PK constraint over the identity column would be a good idea.