Skip to content
Advertisement

H2 Db, ID NextVal

I have a sequence as:

I need to trigger this sequence for OWNER table’s ID column

I tried several versions of NEXTVAL but all gives error

Advertisement

Answer

NUMBER data type is an Oracle compatibility thing, it shouldn’t be normally used in H2 at all, especially for primary keys, this data type is slow. It’s much better to use BIGINT or INTEGER instead.


Normally you should not use sequences too if you don’t need to share the sequence between multiple tables. You can use an identity column:

You can specify sequence options for identity columns too:

START WITH 1 is not very useful, however, because this start value will be used by default.


But if you have a real reason to use the sequence, you need to specify it as a DEFAULT value:

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement