JavaDB SQL reduntant command?

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))

the NOT NULL part is not needed, since the primary key, by default, must be non-zero.

Is this not repeated?

(I'm not sure to just check it out and agree as a result, programming is full of surprises in the long run)

I am using JavaDB / Derby.

+3
source share
1 answer

Yes, the primary key is a combination of a unique index and a nonzero constraint. The latter is defined by the standard SQL99 function E141-08.

It seems that in the old version of Derby, it was not possible to create primary keys unless the columns were declared null:

> PRIMARY KEY does not imply NOT NULL. Derby issues error message:

ij> create table tab (i integer primary key);
ERROR 42831: 'I' cannot be a column of a primary key or unique key because it
can contain null values.

, ​​.

+4

Source: https://habr.com/ru/post/1743365/


All Articles