H2数据库中的自增ID [英] auto increment ID in H2 database

查看:143
本文介绍了H2数据库中的自增ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法为表设置自动递增的 BIGINT ID.可以这样定义

Is there a way to have an auto_incrementing BIGINT ID for a table. It can be defined like so

id bigint auto_increment

但这没有效果(它不会自动增加).我想插入除 ID 字段之外的所有字段 - ID 字段应由 DBMS 提供.还是我需要调用一些东西来增加 ID 计数器?

but that has no effect (it does not increment automatically). I would like to insert all fields but the ID field - the ID field should be provided by the DBMS. Or do I need to call something to increment the ID counter?

推荐答案

它对我有用.JDBC URL:jdbc:h2:~/temp/test2

It works for me. JDBC URL: jdbc:h2:~/temp/test2

drop table test;
create table test(id bigint auto_increment, name varchar(255));
insert into test(name) values('hello');
insert into test(name) values('world');
select * from test; 

结果:

ID  NAME  
1   hello
2   world

这篇关于H2数据库中的自增ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆