Question

I am trying to create a table in an H2 database. How do I specify that the primary key should be generated from a sequence that has been created?

The sequence is called group_seq, and I created it using this statement:

CREATE SEQUENCE GROUP_SEQ;

So when I create the table, how do I specify that I want my primary key col (ID) to use that sequence?

Was it helpful?

Solution

If you want to use your own sequence:

create sequence group_seq;
create table test3(id bigint default group_seq.nextval primary key);

And if not:

create table test1(id identity);

or

create table test2(id bigint auto_increment primary key);

All this is documented in the H2 SQL grammar railroad diagrams.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top