Question

I have an HSQLDB database with a generated ID and I want the auto-incrementing values to always be above 100,000. Is this possible with HSQLDB? Is this possible with any database?

Was it helpful?

Solution

According to the HSQL Documentation:

Since 1.7.2, the SQL standard syntax is used by default, which allows the initial value to be specified. The supported form is( INTEGER GENERATED BY DEFAULT AS IDENTITY(START WITH n, [INCREMENT BY m])PRIMARY KEY, ...). Support has also been added for BIGINT identity columns. As a result, an IDENTITY column is simply an INTEGER or BIGINT column with its default value generated by a sequence generator.

...

The next IDENTITY value to be used can be set with the

ALTER TABLE <table name> ALTER COLUMN <column name> RESTART WITH <new value>;

OTHER TIPS

Here's how to do it in HSQLDB:

The next IDENTITY value to be used can be changed with the following statement. Note that this statement is not used in normal operation and is only for special purposes, for example resetting the identity generator:

ALTER TABLE ALTER COLUMN <column name> RESTART WITH <new value>;

As far as I know, all SQL databases allow you to set a seed value for the auto-increment fields.

Update: Here's a list of identity/auto-increment implementations in the major SQL databases.

It is possible with SQL Server. When defining an auto number column you can define the starting number and the increment:

IDENTITY(100000, 1)

I know it's possible with SQL Server, and I imagine it's possible with others.

With SQL Server you can set the ID column seed (starting number) and increment value.

You can do it with databases that use sequences, like Oracle and PostgreSQL. You specify a start value when you create the sequence.

This suggests that you can do it with HSQL as well.

Not sure about HSQL, but in MS SQL yes it's possible. Set the ID to auto increment and set the seed value to 100,000.

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