Correct me if I am wrong, but this SQL command:
create table MYTABLE (ID INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1))
does not need the NOT NULL part, as a primary key is suppose, by default, to be not null.
Isn’t this reduntant?
(I’m not secure to just test it and agree in the result, programming is full of surprises in long-term)
I’m using JavaDB/Derby.
Yes, a primary key is a combination of a unique index and a non-null constraint. The latter is defined by the SQL99 standard feature E141-08.
It seems that in an older version of Derby it was not possible to create primary keys unless the columns were also declared nullable:
This was a bug and it has been fixed.