开发者

JavaDB SQL command reduntant?

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 开发者_如何学Pythondefault, 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:

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

This was a bug and it has been fixed.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜