简体   繁体   English

在 Derby 数据库中不向主自动增量键插入任何内容

[英]Inserting nothing into primary auto increment key in Derby database

I created table in Derby database that looks something like that:我在 Derby 数据库中创建了如下所示的表:

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.我不想在 id 列中插入任何内容,但我不想被迫总是列出我想要插入的所有列的名称。 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:在 MySQL 和许多其他数据库系统中,我可以这样做:

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.我试着用 NULL 而不是 '' 但我得到了同样的错误。 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?有什么方法可以不将任何内容插入到 Derby 数据库中具有自动增量的主键列中(没有特别列出所有其他列)?

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) (我建议一般指定列,然后 DDL 中列的顺序无关紧要)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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