Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto incrementing ID value

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?

like image 434
mainstringargs Avatar asked Jan 29 '09 14:01

mainstringargs


People also ask

What is auto increment ID?

Auto-increment allows a unique number to be generated automatically when a new record is inserted into a table. Often this is the primary key field that we would like to be created automatically every time a new record is inserted.

How can I get auto increment ID?

To get the next auto increment id in MySQL, we can use the function last_insert_id() from MySQL or auto_increment with SELECT. Creating a table, with “id” as auto-increment. Inserting records into the table. To display all the records.

How can I get auto increment ID in SQL Server?

➞ SQL Server By default, the starting value of IDENTITY is 1, and it will increment by 1 with each new entry unless you tell it otherwise. To start, create a table. The basic syntax: CREATE TABLE TableName ( Column1 DataType IDENTITY(starting value, increment by), Column2 DataType, );

Is identity same as auto increment?

IDENTITY (Auto Increment) The IDENTITY keyword causes the columns to be automatically incremental, meaning that each successive insert into the table will automatically assign a value greater than any previous row of the table. These columns are often referred to as "autoincrement columns".


1 Answers

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>;
like image 89
Tamas Czinege Avatar answered Sep 19 '22 01:09

Tamas Czinege