简体   繁体   中英

Inserting nothing into primary auto increment key in Derby database

I created table in Derby database that looks something like that:

create table "DATABASE".SOMETABLE (ID INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1) CONSTRAINT PK PRIMARY KEY,
                                   SOMETHING VARCHAR(50) not null)

Now I would like to be able to insert into that table without specifically listing all the columns I want to insert into. So I would like to do something like this:

insert into sometable values ('','something')

I don't want to insert anything into id column but I don't want to be forced to always list names of all the columns I want to insert into. However if I execute this code I get error for trying to modify auto increment primary key. In MySQL and many other database systems I could just do this:

insert into sometable values ('','something')

and it would work but Derby gives me an error. I tried putting NULL instead of '' but I just get the same error. Is there any way to not insert anything into the primary key column with auto increment (without specifically listing all the other columns) in Derby database?

Thanks in advance for any answers.

Use:

insert into sometable values (default, 'something')

The default keyword is documented here

Specify the column you're inserting:

insert into sometable (something) values ('something')

(I would recommend specifying columns in general, then the order of the columns in your DDL does not matter)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM