Skip to Main Content

Database Software

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Allow NULLs in PKs

FatMartinRMay 30 2016 — edited May 30 2016

It probably goes back to the dawn of SQL by some purist who had just read Codd, but primary keys should now be allowed to have NULLs - that's not to say the whole PK can be NULL, but its column combinations.    This is already allowed by unique keys, so why not primary keys too?

This inadequacy shows itself up most pertinently with IOTs, making them unusable in such situations.    Ie; we have to revert back to a heap table with a UK on it.

CREATE TABLE ABC_IOT (X VARCHAR2(10), Y VARCHAR2(10), Z VARCHAR2(10),

PRIMARY KEY (X, Y, Z))

ORGANIZATION INDEX

/

INSERT INTO ABC_IOT (X, Y, Z) VALUES ('ABC', 'XYZ', NULL);

Error starting at line : 5 in command -

INSERT INTO ABC_IOT (X, Y, Z) VALUES ('ABC', 'XYZ', NULL)

Error report -

SQL Error: ORA-01400: cannot insert NULL into ("DEV"."ABC_IOT"."Z")

01400. 00000 -  "cannot insert NULL into (%s)"

*Cause:    An attempt was made to insert NULL into previously listed objects.

*Action:   These objects cannot accept NULL values.

CREATE TABLE ABC_HEAP (X VARCHAR2(10), Y VARCHAR2(10), Z VARCHAR2(10),

UNIQUE (X, Y, Z))

/

INSERT INTO ABC_HEAP (X, Y, Z) VALUES ('ABC', 'XYZ', NULL);


1 row inserted.

But, really there is no reason we cannot have NULLs on heap PKs either.

Comments
Post Details
Added on May 30 2016
29 comments
972 views