Creating a table in the h2 database using a predefined sequence for the primary key

I am trying to create a table in an H2 database. How to indicate that the primary key should be generated from the generated sequence?

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

CREATE SEQUENCE GROUP_SEQ; 

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

+8
sequence ddl h2
source share
1 answer

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 of this is documented in the H2 SQL railroad diagrams .

+15
source share

All Articles